錯誤是這樣的:陣列必須是整數(或布爾)類型的
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