python计算分数的浮点数值_如何在scikitlearn MLP分类器中计算分数。得到数字浮点数64不是iterab吗...

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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值