简体   繁体   English

使用 array.reshape(-1, 1) python 重塑数据

[英]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.

相关问题 sklearn:使用 array.reshape(-1, 1) 如果您的数据具有单个特征或使用 array.reshape(1, -1) 如果它包含单个样本来重塑您的数据 - sklearn: 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 如果您的数据具有单个特征,则使用 array.reshape(-1, 1) 重塑您的数据,如果它包含单个样本,则使用 array.reshape(1, -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 如果数据具有单个功能,则可以使用array.reshape(-1,1)重塑数据 - Reshape your data either using array.reshape(-1, 1) if your data has a single feature 预期 2D 数组,得到 1D 数组:array=[5.6 7. ]。 使用 array.reshape(-1, 1) 重塑数据 - Expected 2D array, got 1D array instead: array=[5.6 7. ]. Reshape your data either using array.reshape(-1, 1) ValueError:预期的 2D 数组,得到 1D 数组:array=[19. 27.896 0. 1. 0. ]。 使用 array.reshape(-1, 1) 重塑数据 - ValueError: Expected 2D array, got 1D array instead: array=[19. 27.896 0. 1. 0. ]. Reshape your data either using array.reshape(-1, 1) 使用 array.reshape(-1, 1) 重塑数组 - Reshaping array using array.reshape(-1, 1) 这是什么原因:'ValueError: Expected 2D array, got 1D array instead: & reshape your data using array.reshape(-1, 1)'? - what's the reasons about this:'ValueError: Expected 2D array, got 1D array instead: & reshape your data using array.reshape(-1, 1)'? 出现错误:使用数组重塑数据 - Getting an error: Reshape your data either using array 在Python中使用reshape重塑数组 - Using reshape in Python to reshape an array sci-kit learn:使用 X.reshape(-1, 1) 重塑数据 - sci-kit learn: Reshape your data either using X.reshape(-1, 1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM