【问题标题】:Why my hyperparameters code is not working?为什么我的超参数代码不起作用?
【发布时间】:2020-01-22 18:28:30
【问题描述】:

我正在尝试使用超参数计算来改进我的线性回归,但我的代码不起作用,错误代码编写需要在里面指定 CV,并且在 sckit 导入中找不到里面的参数。

我尝试更改代码但没有成功。

from sklearn.model_selection import GridSearchCV
import random 
import numpy as np

np.random.seed(3456) 

#nr.seed(3456)

## Define the dictionary for the grid search and the model object to search 

param_grid = {"M": [0.0001, 0.001, 0.01, 0.1, 1.0,10.0]}

## Define the linear regression model

#lin_mod = linear_model.LogisticRegression(class_weight = {0:0.45, 1:0.55}) 
lin_mod = linear_model.LinearRegression(fit_intercept = False)

## Perform the grid search over the parameters

clf = ms.GridSearchCV(estimator = lin_mod, param_grid = param_grid, cv = 3, 

scoring = 'roc_auc', return_train_score = True)

 # Use the inside folds

## Fit the cross validated grid search over the data 

clf.fit(train_X, train_y)

## And print the best parameter value

clf.best_estimator_.M

【问题讨论】:

  • 你的问题很不清楚;你到底是什么意思“不工作”?请使用完整的错误消息更新您的帖子

标签: python-3.x machine-learning scikit-learn linear-regression hyperparameters


【解决方案1】:

这三行更改应用于您的代码,可能会让您走得更远

from sklearn.linear_model import LinearRegression


lin_mod = LinearRegression(fit_intercept = False)

clf = GridSearchCV(estimator = lin_mod, param_grid = param_grid, cv = 3,
    scoring = 'roc_auc', return_train_score = True)

【讨论】:

    猜你喜欢
    • 2014-01-23
    • 2013-08-06
    • 2016-01-23
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多