GRID_SEARCH 当需要一维数组时传递了列向量 y

GRID_SEARCH A column-vector y was passed when a 1d array was expected

 #applying grid search to find best performing parameters 
 from sklearn.model_selection import GridSearchCV
 parameters = [{'C':[1, 10, 100, 1000], 'gamma': [ 0.1, 0.2,0.3, 0.5]}]
 grid_search = GridSearchCV(SVC(kernel='rbf' ),  parameters,cv =5, n_jobs= -1)
 grid_search.fit(x_train, y_train)
 ERROR:
/usr/local/lib/python3.6/dist-packages/joblib/externals/loky/process_executor.py:706:
UserWarning: A 
worker stopped while some jobs were given to the executor. This can be caused by a too short worker 
timeout or by a memory leak.
"timeout or by a memory leak.", UserWarning
/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py:760:
DataConversionWarning: A 
column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, 
), for example using ravel().
y = column_or_1d(y, warn=True)
GridSearchCV(cv=5, error_score=nan,
         estimator=SVC(C=1.0, break_ties=False, cache_size=200,
                       class_weight=None, coef0=0.0,
                       decision_function_shape='ovr', degree=3,
                       gamma='scale', kernel='rbf', max_iter=-1,
                       probability=False, random_state=None, shrinking=True,
                       tol=0.001, verbose=False),
         iid='deprecated', n_jobs=-1,
         param_grid=[{'C': [1, 10, 100, 1000],
                      'gamma': [0.1, 0.2, 0.3, 0.5]}],
         pre_dispatch='2*n_jobs', refit=True, return_train_score=False,
         scoring=None, verbose=0)

您需要 select 单列作为 y 定义中的目标,并将 y 转换为 Numpy 数组。例如,如果您有一个如下所示的数据框:

dataframe = data[['feature1', 'feature2', ....'target']]
import numpy as np 
x = np.array(dataframe[['feature1', 'feature2', ...]])
y = np.array(dataframe['target'])