sklearn Logistic Regression “ValueError: Found array with dim 3. Estimator expected <= 2." [英] sklearn Logistic Regression "ValueError: Found array with dim 3. Estimator expected <= 2."
问题描述
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屋!