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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34972142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:48:07  来源:igfitidea点击:

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

pythonscikit-learnlogistic-regression

提问by edwin

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

我试图在这个笔记本中解决这个问题 6。问题是使用 sklearn.linear_model 中的 LogisticRegression 模型,使用 50、100、1000 和 5000 个训练样本对这些数据训练一个简单的模型。 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.

ValueError: 找到带有暗淡 3 的数组。估计器预期 <= 2。

Any idea?

任何的想法?

UPDATE 1: Update the link to the Jupyter Notebook.

更新 1:更新 Jupyter Notebook 的链接。

采纳答案by Kristian K.

scikit-learn expects 2d num arrays for the training dataset for a fitfunction. The dataset you are passing in is a 3d array you need to reshape the array into a 2d.

scikit-learn 需要 2d num 数组作为拟合函数的训练数据集。您传入的数据集是一个 3d 数组,您需要将数组重塑为 2d。

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