sklearn Logistic Regression “ValueError: Found array with dim 3. Estimator expected <= 2." [英] sklearn Logistic Regression &quot;ValueError: Found array with dim 3. Estimator expected &lt;= 2.&quot;

查看:124
本文介绍了sklearn Logistic Regression “ValueError: Found array with dim 3. Estimator expected <= 2."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试解决本笔记本中的这个问题 6.问题是使用 sklearn.linear_model 中的 LogisticRegression 模型,使用 50、100、1000 和 5000 个训练样本在这些数据上训练一个简单的模型.

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.

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: Found array with dim 3. Estimator expected <= 2.

有什么想法吗?

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

UPDATE 1: Update the link to the Jupyter Notebook.

推荐答案

scikit-learn 需要用于 fit 函数.您传入的数据集是一个 3d 数组,您需要将数组重塑为 2d.

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 Regression “ValueError: Found array with dim 3. Estimator expected <= 2."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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