Python data analysis -- realizing linear regression in Python

osc_ s4e6jr85 2021-01-23 12:43:54
python data analysis realizing linear


Linear regression It's one of the basic statistical and machine learning technologies . economic , Computer science , In Social Sciences and so on , Whether it's statistical analysis , Or machine learning , Or scientific computing , There's a huge opportunity to use linear models . I suggest learning it first , And then try something more complicated .

This paper mainly introduces How to step in Python Linear regression is realized in . As for the mathematical derivation of linear regression 、 How does linear regression work , How parameter selection improves the regression model will be explained later .

Return to

Regression analysis is one of the most important fields in statistics and machine learning . There are many regression methods available . Linear regression is one of them . And linear regression is probably one of the most important and widely used regression techniques . This is one of the simplest regression methods . One of its main advantages is that the results obtained by linear regression are very easy to explain . Well, the return mainly includes :

  • Simple linear regression

  • Multiple linear regression

  • Polynomial regression

How to be in python Linear regression is realized in

Use of packages

  • NumPy

NumPy yes Python Basic science software package for , It allows many high-performance operations to be performed on single - and multi-dimensional arrays .

  • scikit-learn

scikit-learn Is in NumPy And some other packages based on the widely used Python Machine learning library . It provides preprocessing data , Reduce the dimension , Return to reality , classification , Clustering and so on .

  • statsmodels

If you want to achieve linear regression and need to function beyond scikit-learn The scope of the , The use of statsmodels Can be used to estimate statistical models , Perform tests, etc .

scikit-learn Simple linear regression of

1. Import used packages And the class

import numpy as np
from sklearn.linear_model import LinearRegression

2. Create data

x = np.array([5, 15, 25, 35, 45, 55]).reshape((-1, 1))
y = np.array([5, 20, 14, 32, 22, 38])

Now we have two arrays : Input x( Regression variables ) and Output y( Predictive variables ), Let's see

>>> print(x)
[[ 5]
[15]
[25]
[35]
[45]
[55]]
>>> print(y)
[ 5 20 14 32 22 38]







You can see x It's two-dimensional and y It's one-dimensional , Because in a more complicated model , There's more than one coefficient . It's here .reshape() To switch .

3. Build a model

Create an instance of a class LinearRegression, It will represent the regression model :

model = LinearRegression()

Now start fitting the model , First you can call .fit() Function to get the optimal

版权声明
本文为[osc_ s4e6jr85]所创,转载请带上原文链接,感谢
https://pythonmana.com/2021/01/20210123123954597Y.html

  1. Mandatory conversion of Python data type
  2. Django reported an error: 'key' ID 'not found in' xxx '. Choices are: xxx'
  3. Python 400 sets of large video, starting from the right direction to learn, a complete set to you
  4. 只需十四步:从零开始掌握Python机器学习(附资源)
  5. Just 14 steps: Master Python machine learning from scratch (resources attached)
  6. Python|文件读写
  7. 安利一个Python界神奇得网站
  8. Python | file reading and writing
  9. Amway is a marvelous website in Python world
  10. 第二热门语言:从入门到精通,Python数据科学简洁教程
  11. The second popular language: from introduction to mastery, python data science concise tutorial
  12. 以我的亲身经历,聊聊学python的流程,同时推荐学python的书
  13. With my own experience, I'd like to talk about the process of learning Python and recommend books for learning python
  14. 以我的亲身经历,聊聊学python的流程,同时推荐学python的书
  15. With my own experience, I'd like to talk about the process of learning Python and recommend books for learning python
  16. Django url 路由匹配过程
  17. Django URL routing matching process
  18. 强者一出,谁与争锋?与Python相比,C++的运行速度究竟有多快?
  19. Who will fight against the strong? How fast is C + + running compared with Python?
  20. python 学习体会
  21. Experience of learning Python
  22. python7、8章
  23. Chapter 7 and 8 of Python
  24. python bool和str转换
  25. python——循环(for循环、while循环)及练习
  26. python变量和常量命名、注释规范
  27. python自定义异常捕获异常处理异常
  28. python 类型转换与数值操作
  29. python 元组(tuple)和列表(list)区别
  30. 解决python tkinter 与 sleep 延迟问题
  31. python字符串截取操作
  32. Python bool and STR conversion
  33. Python -- loop (for loop, while loop) and Practice
  34. Specification for naming and annotating variables and constants in Python
  35. Python custom exception capture exception handling exception
  36. Python type conversion and numerical operation
  37. The difference between tuple and list in Python
  38. Solve the delay problem of Python Tkinter and sleep
  39. Python string interception operation
  40. Python 100天速成中文教程,GitHub标星7700
  41. Python 100 day quick Chinese course, GitHub standard star 7700
  42. 以我的親身經歷,聊聊學python的流程,同時推薦學python的書
  43. With my own experience, I'd like to talk about the process of learning Python and recommend books for learning python
  44. python爬虫获取起点中文网人气排行Top100(快速入门,新手必备!)
  45. Python crawler to get the starting point of Chinese network popularity ranking Top100 (quick start, novice necessary!)
  46. 【Python常用包】itertools
  47. Itertools
  48. (国内首发)最新python初学者上手练习
  49. (国内首发)最新python初学者上手练习
  50. (first in China) the latest practice for beginners of Python
  51. (first in China) the latest practice for beginners of Python
  52. (数据科学学习手札104)Python+Dash快速web应用开发——回调交互篇(上)
  53. (data science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  54. (数据科学学习手札104)Python+Dash快速web应用开发——回调交互篇(上)
  55. (data science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  56. (資料科學學習手札104)Python+Dash快速web應用開發——回撥互動篇(上)
  57. (materials science learning notes 104) Python + dash rapid web application development -- callback interaction (Part 1)
  58. Python OpenCV 图片高斯模糊
  59. Python OpenCV image Gaussian blur
  60. Stargan V2: converse image synthesis for multiple domains reading notes and Python code analysis