错误是这样的:
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
,然后我得到这个错误,可以有人帮我解决这个问题吗?非常感谢!