线性回归python_python线性回归的终极初学者指南

本文是针对初学者的Python线性回归全面指南,详细介绍了如何使用Python进行线性回归分析。
摘要由CSDN通过智能技术生成

线性回归python

Machine Learning is making the computer learn from studying data and statistics. Machine Learning is a step into the direction of artificial intelligence (AI). Machine Learning is a program that analyses data and learns to predict the outcome.

机器学习使计算机从研究数据和统计信息中学习。 机器学习是迈向人工智能(AI)方向的一步。 机器学习是一个程序,可以分析数据并学习预测结果。

什么是回归? (What is Regression?)

The term regression is used when you try to find the relationship between variables. In Machine Learning and statistical modelling, that relationship is used to predict the outcome of future events.

当您尝试查找变量之间的关系时,将使用术语回归。 在机器学习和统计建模中,该关系用于预测未来事件的结果。

Linear Regression

线性回归

Linear regression uses the relationship between the data-points to draw a straight line through all them. This line can be used to predict future values.

线性回归使用数据点之间的关系在所有数据点之间画一条直线。 这条线可以用来预测未来价值。

入门 (Getting Started)

Python has methods for finding a relationship between data-points and to draw a line of linear regression. We will show you how to use these methods instead of going through the mathematic formula.

Python提供了一些方法来查找数据点之间的关系并绘制线性回归线。 我们将向您展示如何使用这些方法而不是通过数学公式。

An example:

一个例子:

x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]plt.scatter(x, y)
plt.show()

This displays a scatter plot:

这将显示一个散点图:

Image for post

Import ‘scipy’ and draw the line of Linear Regression:

导入“ scipy”并绘制线性回归线:

import matplotlib.pyplot as plt
from scipy import stats

Create the arrays that represent the values of the x and y-axis:

创建表示x和y轴值的数组:

x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]

Execute a method that returns some critical fundamental values of Linear Regression:

执行一个返回线性回归的一些关键基本值的方法:

slope, intercept, r, p, std_err = stats.linregress(x, y)

Create a function that uses the ‘slope’ and ‘intercept’ values to return a new deal. This new value represents where on the y-axis, the corresponding x value will be placed:

创建一个使用“ slope”和“ intercept”值返回新交易的函数。 这个新值表示将在y轴上放置相应的x值:

def myfunc(x):
return slope * x + intercept

Run each value of the x array through the function. This will result in a new collection with new values for the y-axis:

通过函数运行x数组的每个值。 这将导致新集合具有y轴的新值:

mymodel = list(map(myfunc, x))

Draw the original scatter plot:

绘制原始散点图:

plt.scatter(x, y)

Draw the line of linear regression:

画出线性回归线:

plt.plot(x, mymodel)

Display the diagram:

显示图:

plt.show()

If you are interested in the full story about Machine learning check out this:

如果您对有关机器学习的完整故事感兴趣,请查看以下内容:

结论 (Conclusion)

I hope after this article you have a basic understanding of Linear Regression and how to use it in Python and that you will be able to run yourself some scripts of Machine Learning now!

希望本文之后您对线性回归有基本的了解,以及如何在Python中使用它,并且现在您可以运行一些机器学习脚本!

翻译自: https://levelup.gitconnected.com/the-ultimate-beginners-guide-to-linear-regression-in-python-840c23151475

线性回归python

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值