1
我的CSV數據如下:交叉驗證不兼容形狀
0.03095566878715169,False
0.9700097239723956,False
0.9756176662740987,False
0.9516273399151274,False
0.21111951544035354,False
0.10371038060888567,False
0.018505911665029413,True
0.3595877911788813,True
0.010223522470333259,True
0.0812290660300292,True
0.19798744613629704,True
我想獲得一個k重交叉驗證得分。
這是我的代碼如下:
import os,csv
import numpy as np
from sklearn import cross_validation
from sklearn import datasets
from sklearn import svm
import numpy as np
csvout = open('xval.csv','wb')
csvwriter=csv.writer(csvout)
f='some.csv'
try:
X,Y=[],[]
feat=f[4:-4]
print feat
csvin = open(f,'rb')
csvread=csv.reader(csvin)
for row in csvread:
X.append(row[0])
Y.append(row[1])
npX=np.array(X)
npY=np.array(Y)
clf = svm.SVC()
xval_score=cross_validation.cross_val_score(clf,X=npX,y=npY,cv=10)
csvwriter.writerow([feat,str(xval_score[-1])])
except Exception,e:
print(e)
csvout.close()
但是,我得到一個錯誤如下:
X and y have incompatible shapes.
X has 1 samples, but y has 837
或者我要對這個錯誤的方式?如果有人能夠對此進行更多闡述,我將不勝感激。