Home > Backend Development > Python Tutorial > Can python do regression?

Can python do regression?

little bottle
Release: 2020-09-17 13:37:38
Original
2831 people have browsed it

Python can implement linear regression. The implementation method is: 1. Call linear_model in the scikit-learn library to fit the data; 2. Use Scipy.polyfit() or numpy.polyfit(); 3. Use highly professional The linear regression function Stats.linregress().

Can python do regression?

Linear regression is a veteran model in the data science community. It is almost a required introductory course for all data scientists. Putting aside the model analysis and testing involving a large amount of data, can you really apply linear regression proficiently? Below I will introduce to you several ways to implement regression in Python.

Method 1: Call linear_model from the scikit-learn library

Due to the widespread popularity of the machine learning library scikit-learn, a common method is to call linear_model from the library. Fit the data.

While this can provide other advantages of other pipeline features of machine learning (e.g.: data normalization, model coefficient regularization, passing a linear model to another downstream model), when a data analyst needs This is usually not the quickest and easiest way to determine regression coefficients (and some basic related statistics) quickly and easily.

Method 2: Scipy.polyfit( ) or numpy.polyfit( )

This is the most basic least squares polynomial fit function (least squares polynomial fit function), accepts a data set and a polynomial function of any dimension (specified by the user), and returns a set of coefficients that minimizes the squared error.

For simple linear regression, you can choose a 1-dimensional function. But if you want to fit a higher dimensional model, you can build polynomial features from the linear feature data and fit the model.

Method 3: Stats.linregress( )

This is a highly specialized linear regression function that can be found in the statistics module of SciPy. However, because it is only used to optimize the least squares regression of two sets of measured data, its flexibility is quite limited. Therefore, you cannot use it for generalized linear model and multiple regression fitting.

However, due to its specificity, it is one of the fastest methods in simple linear regression. In addition to the fitted coefficients and intercept terms, it also returns basic statistics such as the R2 coefficient and standard deviation.

The above is the detailed content of Can python do regression?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template