Python machine learning Ridge regression

Source: Internet
Author: User

#岭回归主要是弥补在数据中出现异常值时, improve the stability of linear model, that is, robustness robust

Import Pandas as PD

Import NumPy as NP

Import Matplotlib.pyplot as Plt

From Sklearn import Linear_model

Import Sklearn.metrics as SM

#直接拿最小二乘法数据

Ridgerg=linear_model. Ridge (alpha=0.5,fit_intercept=true,max_iter=10000) #alpha nearer to 0, the more the ridge regression approached the linear regression.

Ridgerg.fit (X_train,y_train) #训练模型

Y_train_pred=ridgerg.predict (X_train) #模型y值

Y_test_pred=ridgerg.predict (x_test) #模型预测y值

ridgerg.coef_# Printing Model Parameters

ridger.intercept_# Intercept Items

Print (' r2= ', Sm.r2_score (y_test,y_test_pred)) #得到R2

#模型超参数的训练

Python machine learning Ridge regression

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.