[英]What does norm='l2' in sklearn.preprocessing.normalize do for matrix normalization?
I normalized scipy.sparse
matrix sA
here by using sklearn.preprocessing.normalize
. 我在这里通过使用sklearn.preprocessing.normalize
scipy.sparse
矩阵sA
了归一化。 I read the document but not understand about norm='l...'
well, so I tested it. 我阅读了该文档,但是对norm='l...'
理解却不够,所以我对其进行了测试。
norm='l1'
went ok and I got the sum result as expected as 1 in all row. norm='l1'
正常,我在所有行中得到的期望结果为1。
A = np.array([[1,2,0],[0,0,3],[1,0,4]])
sA = sp.csr_matrix(A)
normsA = normalize(sA, norm='l1', axis=0)
print normsA
print "---"
print sum(normsA)
>>(0, 0) 0.5
(2, 0) 0.5
(0, 1) 1.0
(1, 2) 0.428571428571
(2, 2) 0.571428571429
---
(0, 0) 1.0
(0, 1) 1.0
(0, 2) 1.0
However, when I tried l2
, I can't find how it is normalizing the matrix. 但是,当我尝试l2
,我找不到它如何对矩阵进行归一化。 Sum of the matrix or the transposed matrix is not equal to one. 矩阵或转置矩阵的总和不等于1。 What l2
does for normalizing here? l2
对这里的归一化有什么作用?
normsA2 = normalize(sA, norm='l2', axis=0)
print sum(normsA2)
print sum(normsA2.T)
>>(0, 0) 1.41421356237
(0, 1) 1.0
(0, 2) 1.4
(0, 0) 1.70710678119
(0, 1) 0.6
(0, 2) 1.50710678119
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.