我试图返回我的逻辑回归模型的系数。以下是我创建模型的方式:
logreg = LogisticRegression(solver = 'liblinear')
model = GridSearchCV(logreg, cv = 3, param_grid = {
'penalty': ('l1', 'l2'),
'C': [0.5, 0.6, 0.7, 0.8, 0.9],
'max_iter': [100]
})
model.fit(X_train, y_train)
model.coef_ # here is where I get the error
# Validation (test)
y_pred = model.predict(X_test)
但我得到了以下错误:
AttributeError: 'GridSearchCV' object has no attribute 'coef_'
我甚至尝试了.best_score_和其他函数,看看是否可以用另一种方法找到系数。但是没有运气。你知道我怎样才能解决这个问题吗
我认为您正在寻找
GridSearchCV
提供的最佳模型:您的模型只是一个
GridSearchCV
对象,而coef_
是一个logreg对象的属性。best_estimator_
属性是在网格搜索期间发现的具有最高精度的估计器您必须选择一个特定的估计器来访问
coef_
属性。尝试:{}对象本身没有系数,因为它不是一个估计器,它是一个循环参数并训练各种估计器的对象
相关问题 更多 >
编程相关推荐