我在Python中有以下代码和错误:
我只想要train_X
的第一行和t rain_y
的第一行来训练SVM模型......
(我想通过逐个从Iris数据集中提取数据来按顺序训练数据模型)
CODE:
np.random.seed(1)
iris = pd.read_csv("Iris.csv")
iris.drop("Id", axis=1, inplace = True)
iris = iris.values
train, test = train_test_split(iris, test_size=0.3) # our main data split
into train and test
i=0
train_X1 = train_X[i:i+1,:]
train_y1 = train_y[i]
model = svm.SVC() # select the svm algorithm
# we train the algorithm with training data and training output
model.fit(train_X1, train_y1)
# we pass the testing data to the stored algorithm to predict the outcome
prediction = model.predict(test_X)
print('The test accuracy of the SVM is :',
metrics.accuracy_score(prediction,test_y))
# we check the accuracy of the algorithm
ERROR:
ValueError Traceback(最近一次调用最后一次)
in()
8#我们用训练数据和训练输出训练算法 ----> 9 model.fit(train_X1,train_y1)147 self._sparse = sparse and not callable(self.kernel)
- > 149 X,y = check_X_y(X,y,dtype = np.float64,order ='C',accept_sparse ='csr')150 y = self._validate_targets(y)
545 dtype=None) 546 else:
- > 547 y = column_or_1d(y,warn = True)548 _assert_all_finite(y)549如果y_numeric和y.dtype.kind =='O':
581 return np.ravel(y)
- > 583引发ValueError(“输入形状错误{0}”。格式(形状)) ValueError:输入形状错误()