python - sklearn 逻辑回归 "ValueError: Found array with dim 3. Estimator expected <= 2."

标签 python scikit-learn logistic-regression

我试图解决 this problem 6 in this notebook .问题是使用来自 sklearn.linear_model 的 LogisticRegression 模型,使用 50、100、1000 和 5000 个训练样本来训练一个简单的模型。

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

这是我试图做的代码,它给了我错误。

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

有什么想法吗?

最佳答案

scikit-learn 期望 fit 的训练数据集有 2d 个 num 数组。功能。您传入的数据集是一个 3d 数组,您需要将数组 reshape 为 2d。

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

关于python - sklearn 逻辑回归 "ValueError: Found array with dim 3. Estimator expected <= 2.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34972142/

相关文章:

python - numpy 索引 : fixed length parts of each row with varying starting column

python - Mutual_info_regression 和 Mutual_info_classif 有什么用?

python - 通过 RandomizedLogisticRegression 查找选定的特征

machine-learning - sklearn 聚类输出是否因机器而异?

python - Python sklearn coef_ 输出中的 target 是什么?

python - 逻辑回归统计模型概率预测的置信区间

python - 如何根据sklearn中的列值拆分数据

python - 属性错误 : 'dict' object has no attribute 'endswith'

Python Pandas 滚动函数

java - 程序终止,没有任何错误