[英]Reshape your data either using array.reshape(-1, 1) python
Hi i need your help with this mistake:嗨,我需要你的帮助来解决这个错误:
ValueError: Expected 2D array, got 1D array instead:
array=[0. 0. 0. ... 0. 0. 1.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
The code are:代码是:
train, test = train_test_split(dataset_ordenado, test_size = 0.30, random_state = 20201122)
Objetivo_train=train['results']
Objetivo_test=test['results']
Indep_train=train.drop(['results'],axis=1)
Indep_test=test.drop(['results'],axis=1)
TS = TimeSeriesSplit(n_splits = 5)
dt = DecisionTreeClassifier()
grid = {'max_depth': [5,7,9,11,15], 'min_samples_leaf': [5,7,9,11,13],'criterion': ['gini', 'entropy']}
gs = GridSearchCV(dt, param_grid=grid, cv=TS)
gs.fit(Objetivo_train, Indep_train)
train, test = train_test_split(dataset_ordenado, test_size = 0.30, random_state = 20201122)
y_train=train['results']
y_test=test['results']
X_train=train.drop(['results'],axis=1)
X_test=test.drop(['results'],axis=1)
TS = TimeSeriesSplit(n_splits = 5)
dt = DecisionTreeClassifier()
grid = {'max_depth': [5,7,9,11,15], 'min_samples_leaf': [5,7,9,11,13],'criterion': ['gini', 'entropy']}
gs = GridSearchCV(dt, param_grid=grid, cv=TS)
gs.fit(X_train, y_train)
I think this will work.我认为这会奏效。 You need to put the features (X_train) and then the target column (y_train) in the fit function.
您需要将特征 (X_train) 和目标列 (y_train) 放入拟合 function 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.