I have a data set(19 attributes and 1700 instances),I am training Logistic regression, decision tree, random forest on it. logistic regression works fine but when I try decision trees I get the error:
Expected 2D array, got 1D array instead:
array=[1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0.
0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 1. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0.
data = data.interpolate()
print(data.isnull().sum())
data['Year_upd'].fillna('0', inplace=True)
data['Month_upd'].fillna('0', inplace=True)
data['Day_upd'].fillna('0', inplace=True)
data['Hour_upd'].fillna('0', inplace=True)
print(data.isnull().sum())
x = data.drop(labels='Type', axis='columns')
y = data.iloc [:, 13]
x.head()
x_train, x_test, y_train, y_test = train_test_split(x, y ,test_size = 0.2,)
model = LogisticRegression(max_iter = 4000)
model.fit (x_train, y_train)
model3= tree.DecisionTreeClassifier()
model3.fit(x_train,y_train)
I tried using the following code to fix the issue
model3= tree.DecisionTreeClassifier()
model3.fit(x_train.values.reshape(-1, 1),y_train)
and I still get: Number of labels=1424 does not match number of samples=29904