我试图解决 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/