sklearn Logistic回归" ValueError:找到的数组为暗3.估计器预期< == 2. [英] sklearn Logistic Regression "ValueError: Found array with dim 3. Estimator expected <= 2."

查看:942
本文介绍了sklearn Logistic回归" ValueError:找到的数组为暗3.估计器预期< == 2.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在此笔记本中解决此问题6.问题是通过使用来自sklearn.linear_model的LogisticRegression模型,使用50、100、1000和5000个训练样本在此数据上训练一个简单的模型. https://github.com/tensorflow/examples/blob/master /courses/udacity_deep_learning/1_notmnist.ipynb

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:找到的数组为暗3.估计值应为< = 2.

ValueError: Found array with dim 3. Estimator expected <= 2.

有什么主意吗?

更新1:更新指向Jupyter Notebook的链接.

UPDATE 1: Update the link to the Jupyter Notebook.

推荐答案

scikit-learn期望2a num数组用于

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

这篇关于sklearn Logistic回归&quot; ValueError:找到的数组为暗3.估计器预期&lt; == 2.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆