Sklearn Regression Simple Example

Source: Internet
Author: User

1. Linear regression:

Import pandas as PD
import NumPy as NP
from Sklearn import Linear_model as LM

#准备数据, the Fit function requires X to be a matrix, and the y term is a sequence, so only a single Variable needs to be transpose
A=pd.read_excel (R ' D:\baidu\Desktop\1.xls ')
b=a.icol (1)
b=[[x] for x in B] #或者b =b.reshape (len (b) , 1)
C=a.icol (2)

#训练模型
f=lm. Linearregression ()
f1=f.fit (b,c)

#获得结果
c,i,p=f1.coef_,f1.intercept_,f1.predict #f1. Coef_ as a factor, Intercept_ is a constant term, predict () gets the predictive result
print (c,i,p)


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.