Python 如何计算scikit learn MLPC分类器中的分数。无法获取numpy.float64
我正在使用scikit学习MLPC分类器(神经网络)对一些图像进行分类。 图像数据作为多维浮点数组返回。如果我不将1热编码标签转换为浮动,则在尝试训练模型时会出现标签不匹配,因此我会转换它们。然而,当我去给预测打分时,现在我得到“'numpy.float64'对象不可编辑”。有什么建议可以让它发挥作用吗Python 如何计算scikit learn MLPC分类器中的分数。无法获取numpy.float64,python,scikit-learn,Python,Scikit Learn,我正在使用scikit学习MLPC分类器(神经网络)对一些图像进行分类。 图像数据作为多维浮点数组返回。如果我不将1热编码标签转换为浮动,则在尝试训练模型时会出现标签不匹配,因此我会转换它们。然而,当我去给预测打分时,现在我得到“'numpy.float64'对象不可编辑”。有什么建议可以让它发挥作用吗 import numpy as np import sys import pandas as pd from skimage import io from skimage import tran
import numpy as np
import sys
import pandas as pd
from skimage import io
from skimage import transform as trans
from sklearn.neural_network import MLPClassifier as NN
from sklearn.model_selection import train_test_split
#Get the data
print ("Reading CSV...")
data = pd.read_csv(filepath_or_buffer="hot_dog_data.csv", nrows=30)
X = data.values[1:,0]
Y = data.values[1:,1:8]
#convert the images to RGB number arrays
print ('Converting Images...')
img_converts = []
for line in X:
img = io.imread("./images/"+line)
img = trans.resize(img,(300,400), mode='constant')
img_converts.append(img)
X = np.array(img_converts)
# Split into train and test vars
trainX, testX, trainY, testY = train_test_split(X,Y, test_size=0.17)
# Reshape the image arrays into 2-D arrays so it will fit the model
xa, xb, xc, xd = trainX.shape
d2_trainX = trainX.reshape((xa, xb*xc*xd))
xe, xf, xg, xh = testX.shape
d2_testX = testX.reshape((xe, xf*xg*xh))
clf = NN(solver='lbfgs',hidden_layer_sizes=(5, 2), random_state=1)
# Recast the Y data so the fit won't get a label mismatch
trainY = np.asarray(trainY, dtype=np.float)
testY = np.asarray(testY, dtype=np.float)
print ('The machine is learning...')
clf.fit(d2_trainX, trainY)
print ('Predicting...')
count = 1
for line in clf.predict(d2_testX):
print (count, line )
count += 1
print 'Calculating Accuracy...'
count = 1
for x,line in clf.score(d2_testX, testY):
print (count, line)
sys.exit()
排队
for x,line in clf.score(d2_testX, testY):
您正在尝试迭代score()
返回的浮点值
分数(X,y,样本重量=无)
返回:分数:浮动
在x的
行中,clf.score(d2\u testX,testY)中的行中:
您试图迭代score()返回的浮点值。[参见文档]()。哈哈,这是循环,而不是score函数。想添加你的评论作为解决方案,这样我就可以标记它了?哦,它返回一个浮点。这样做更有意义。