arrays - what is numpy.ndarray without column in python? -


i saw sample:

from sklearn import cross_validation sklearn import metrics sklearn import svm sklearn import datasets iris = datasets.load_iris() clf = svm.svc(kernel='linear', c=1) predicted = cross_validation.cross_val_predict(clf, iris.data,iris.target, cv=10) metrics.accuracy_score(iris.target, predicted)  

so wrote:

from sklearn import cross_validation sklearn import metrics sklearn import svm clf = svm.svc(kernel='linear', c=1) train_data_input=train_df.iloc[:,1:].values train_data_output=train_df[[0]].values predicted = cross_validation.cross_val_predict(clf, train_data_input,train_data_output, cv=10) metrics.accuracy_score(train_data_output, predicted)  

but got error:
indexerror: many indices array.

i think, problem relate type of "train_data_output". whilst see these types:

type(train_data_output) out[32]: numpy.ndarray  type(iris.target) out[33]: numpy.ndarray 

but in "spyder>variable explorer window" can see difference, in "size" column show variable has column (891,1), in sample variable there isn't column (150,)!!!

train_data_input.shape out[34]: (891, 12)  train_data_output.shape out[35]: (891, 1)  predicted.shape out[36]: (150,)  iris.target.shape out[37]: (150,) 

by comment @shanmuga solve problem in way:

train_data_output=np.reshape(train_data_output, (891,)) 

but how extract column datafram don't need command?


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -