python的网格搜索,一直报错 IndexError: too many indices for array,大神们求教了
# 导入pandas与numpy工具包。
import pandas as pd
import numpy as np
# 使用pandas.read_csv函数读取文件夹kk数据。
X_test= pd.read_csv('N:/kk/X_test.csv' )
Y_test= pd.read_csv('N:/kk/Y_test.csv' )
X_train= pd.read_csv('N:/kk/X_train.csv')
Y_train= pd.read_csv('N:/kk/Y_train.csv')
# 从sklearn.preprocessing里导入数据标准化模块。
from sklearn.preprocessing import StandardScaler
# 对训练和测试的特征数据进行标准化。
ss = StandardScaler()
X_train = ss.fit_transform(X_train)
X_test = ss.transform(X_test)
from sklearn.svm import SVC
svc=SVC()
svc
parameters = { 'svc__gamma': np.logspace(-1, 1, 4),'svc__C': np.logspace(-1, 1, 3)}
# 从sklearn.grid_search中导入网格搜索模块GridSearchCV。
from sklearn.grid_search import GridSearchCV
# 将12组参数组合包括3折交叉验证的要求全部告知GridSearchCV。
gs = GridSearchCV(estimator =svc ,param_grid =parameters,verbose=2,refit=True, cv=3)
# 执行单线程网格搜索。
gs.fit(X_train, Y_train)
gs.best_params_, gs.best_score_
# 输出最佳模型在测试集上的准确性。
print gs.score(X_test, Y_test)
IndexError Traceback (most recent call last)
<ipython-input-26-dc31eeebaf33> in <module>()
7
8 # 执行单线程网格搜索。
----> 9 gs.fit(X_train, Y_train)
10 gs.best_params_, gs.best_score_
11
IndexError: too many indices for array
.
.
.