我正在尝试运行此代码。
import csv
import numpy as np
from sklearn import svm, datasets, cross_validation
from sklearn.grid_search import GridSearchCV
###Load Training Data
trainTargetArray = []
trainDataArray = []
with open('ocp_training.csv', 'r') as trainFile:
trainReader = csv.reader(trainFile, delimiter = ',')
for row in trainReader:
trainTargetArray.append(row[0])
trainDataArray.append(row[1:])
#Delete column headers
del trainTargetArray[0]
del trainDataArray[0]
trainData = np.array(trainDataArray)
trainTarget = np.array(trainTargetArray)
trainData = trainData.astype(np.float)/255.0
trainTarget = trainTarget.astype(np.float)
###Load Testing Data
testDataArray = []
with open('ocp_testing.csv', 'r') as testFile:
testReader = csv.reader(testFile, delimiter = ',')
for row in testReader:
testDataArray.append(row)
#Delete column headers
del testDataArray[0]
testData = np.array(testDataArray)
testData = testData.astype(np.float)/255.0
#Set up classification and fit the model data
svc = svm.SVC(gamma=0.128, C=1)
svc.fit(trainData, trainTarget)
#Predict/Determine Value of New Images
prediction = svc.predict(testData)
#Save output to file
output = open('./output.csv', 'w')
for x, value in np.ndenumerate(prediction):
output.write(str(int(value)))
output.write("\n")
output.close()
当我尝试运行此代码时,它给了我这个错误 Traceback(最近一次调用最后一次):** IDLE Internal Exception: File "C:\Python34\lib\idlelib\run.py", line 353, in runcode exec(代码,self.locals) 文件“C:\Python34\run.py”,第 20 行,在 trainData = trainData.astype(np.float)/255.0 ValueError: 设置具有序列的数组元素。