AttributeError:'numpy.ndarray'对象没有属性'lower'拟合逻辑模型数据

时间:2016-05-31 14:02:24

标签: python numpy scikit-learn

我正在运行此代码:

from sklearn import cross_validation
import numpy as np
import sys
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import datasets, svm, metrics

digits = datasets.load_digits()

X_train, X_test, y_train, y_test = cross_validation.train_test_split(
digits.data, digits.target, test_size=0.4, random_state=0)

clf = linear_model.LogisticRegression(X_train, y_train) 
clf.fit(X_train, y_train)

我收到此错误:

  

AttributeError:'numpy.ndarray'对象没有属性'lower'

如何使逻辑模型适合?

2 个答案:

答案 0 :(得分:1)

您不应将X_trainy_train传递给LogisticRegression构造函数。你需要

...

clf = linear_model.LogisticRegression() 
clf.fit(X_train, y_train)

答案 1 :(得分:0)

clf = LogisticRegression() clf.fit(x_train,x_test)

不要在LogisticRegression模型内部传递参数