I attempt to solve this problem 6 in this notebook. The question is to train a simple model on this data using 50, 100, 1000 and 5000 training samples by using the LogisticRegression model from sklearn.linear_model
.
JavaScript
x
3
1
lr = LogisticRegression()
2
lr.fit(train_dataset,train_labels)
3
This is the code i trying to do and it give me the error.
JavaScript
1
2
1
ValueError: Found array with dim 3. Estimator expected <= 2.
2
Any idea?
Advertisement
Answer
scikit-learn expects 2d num arrays for the training dataset for a fit function. The dataset you are passing in is a 3d array you need to reshape the array into a 2d.
JavaScript
1
3
1
nsamples, nx, ny = train_dataset.shape
2
d2_train_dataset = train_dataset.reshape((nsamples,nx*ny))
3