Ultiseeker
Ultiseeker

Reputation: 181

Is it possible to tune the linear regression (hyper)parameter in sklearn

I'm starting to learn a bit of sci-kit learn and ML in general and i'm running into a problem. I've created a model using linear regression. the .score is good (above 0.8) but i want to get it better (perhaps to 0.9). I've searched the documentation of sklearn and googled this question but I cannot seem to find the answer.

My question is: Is it possible to tune the LinearRegression model? and if so, where can I find it?

#----- Forecast in hours -----#
forecast_out = 48


#----- Import and prep data -----#
using pandas to create X and y
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

#----- Linear Regression-----#
lr = LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)

lr.fit(x_train, y_train)
lr_confidence = lr.score(x_test, y_test)
print("lr confidence: ", lr_confidence)
x_forecast = np.array(data.drop(['Prediction'],1))[-forecast_out:]
lr_prediction = lr.predict(x_forecast)

Upvotes: 1

Views: 34977

Answers (3)

Ignacio Arizna
Ignacio Arizna

Reputation: 21

No, it is not possible. For Hyperparams tune Linear Regressions, try Lasso, Ridge or ElasticNet

Upvotes: 0

soham_dhole
soham_dhole

Reputation: 69

It seems that sklearn.linear_model.LinearRegression does not have hyperparameters that can be tuned. So, instead please use sklearn.linear_model.SGDRegressor, which will provide many possiblites for tuning hyperparameters. Its documentation can be found here: https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDRegressor.html .

Upvotes: 1

Vaidøtas I.
Vaidøtas I.

Reputation: 554

There is always room for improvement. Parameters are there in the LinearRegression model. Use .get_params() to find out parameters names and their default values, and then use .set_params(**params) to set values from a dictionary. GridSearchCV and RandomSearchCV can help you tune them better than you can, and quicker.

This is a very open-ended question and you should just look up the documentation. It's all there, really, trust me - I've looked. Just Google LinearRegression documentation.

http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

Upvotes: 5

Related Questions