Reshape your data either using array.reshape(-1, 1) python

Viewed 107

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)
1 Answers

I found the mistake, i download the information from aws in pickle data and i dont see that all was in objet type so i need to convert all values in number.

I post the transformation code of all the columns in number in case someone enters and serves

I GET THE VARIABLES IN LIST FORM columns_names = dataset_ordenado.columns.values[1:]

columns_names_list = list(columns_names)

TRANSFORM dataset_ordenado[columns_names_list]=dataset_ordenado[columns_names_list].apply(pd.to_numeric)

Related