错误是这样的:阵列必须是整数(或布尔)类型的
Traceback (most recent call last):
File "NearestCentroid.py", line 53, in <module>
clf.fit(X_train.todense(),y_train)
File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.13.1-py2.7-linux-i686.egg/sklearn/neighbors/nearest_centroid.py", line 115, in fit
variance = np.array(np.power(X - self.centroids_[y], 2))
IndexError: arrays used as indices must be of integer (or boolean) type
码是这样的:
distancemetric=['euclidean','l2']
for mtrc in distancemetric:
for shrkthrshld in [None]:
#shrkthrshld=0
#while (shrkthrshld <=1.0):
clf = NearestCentroid(metric=mtrc,shrink_threshold=shrkthrshld)
clf.fit(X_train.todense(),y_train)
y_predicted = clf.predict(X_test.todense())
我使用scikit-learn
包,X-train
,y_train
是在LIBSVM格式中,X
是特征:值对,y_train
是目标/标签,X_train
是CSR基本格式,shrink_threshold
不支持CSR稀疏矩阵,因此我将.todense()
到X_train
,然后我得到了这个错误,有谁能帮我解决这个问题吗?非常感谢!
'y_train'的价值是什么? – mbatchkarov
我也见证了相同功能的参数略有不同的错误。 – bearrito
您应该接受答案 – vumaasha