Simple linear regression analysis of Python

Source: Internet
Author: User

Use the Linear_model of the Sklearn library. Linearregression (), can be very simple linear regression analysis

Here is the code:

1 #Import the Linear_model class under the Sklearn library2  fromSklearnImportLinear_model3 #Import Pandas Library, alias for PD4 ImportPandas as PD5 6filename = r'D:\test.xlsx'7 #reading data Files8data =pd.read_excel (filename)9 Ten #transform the argument data into a matrix Onex = data.iloc[:,:1].values A #transformation dependent variable data as matrix -y = data.iloc[:,2].values - #print (x) the #print (y) -  - #call a linear regression function -CLF =Linear_model. Linearregression () + #Start linear regression calculation - clf.fit (x, y) + #get slope A Print(clf.coef_[0]) at #Get intercept - Print(Clf.intercept_)

Simple linear regression analysis of Python

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.