Python SVC:索引器的网格搜索错误:数组的索引太多
我正在尝试使用Python SVC:索引器的网格搜索错误:数组的索引太多,python,scikit-learn,svm,grid-search,svc,Python,Scikit Learn,Svm,Grid Search,Svc,我正在尝试使用GridSearchCV为SVC找到最佳参数 from sklearn.svm import SVC from sklearn import svm, grid_search from sklearn.model_selection import GridSearchCV param_grid = [ {'C': [1,5,10,100]}, ] algo = SVC(kernel="poly", degree=5, coef0=2) grid_
GridSearchCV
为SVC
找到最佳参数
from sklearn.svm import SVC
from sklearn import svm, grid_search
from sklearn.model_selection import GridSearchCV
param_grid = [
{'C': [1,5,10,100]},
]
algo = SVC(kernel="poly", degree=5, coef0=2)
grid_search = GridSearchCV(algo, param_grid, cv=3, scoring='neg_mean_squared_error')
grid_search.fit(X_train, y_train)
print(grid_search.best_params_) #line 162
我得到以下错误:
File "main.py", line 162, in <module>
IndexError: too many indices for array
我得到一个分数。接受目标值作为一个数组,如y
形状[n\u样本]
或[n\u样本,n\u输出]
在您的情况下,(892,)
。因此,对y\U列车进行重塑:
y_train = y_train.reshape(892,)
y\u train.shape
的输出是什么?y\u train.shape的输出是(892,1),X\u train.shape的输出是(892,14)在grid\u search.fit(X\u train,y\u train)
之前使用y\u train=y\u train.重塑(892,)
。现在有错误吗?是的!!谢谢出了什么问题?为什么(892,)有效(没有其他属性),而(892,1)无效?
y_train = y_train.reshape(892,)