sklearn Logistic Regression “ValueError: Found array with dim 3. Estimator expected <= 2.”

百般思念 提交于 2019-11-26 13:49:37

问题


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. https://github.com/tensorflow/examples/blob/master/courses/udacity_deep_learning/1_notmnist.ipynb

lr = LogisticRegression()
lr.fit(train_dataset,train_labels)

This is the code i trying to do and it give me the error. ValueError: Found array with dim 3. Estimator expected <= 2.

Any idea?

UPDATE 1: Update the link to the Jupyter Notebook.


回答1:


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.

nsamples, nx, ny = train_dataset.shape
d2_train_dataset = train_dataset.reshape((nsamples,nx*ny))


来源:https://stackoverflow.com/questions/34972142/sklearn-logistic-regression-valueerror-found-array-with-dim-3-estimator-expec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!