Research Snappy
  • Market Research Forum
  • Investment Research
  • Consumer Research
  • More
    • Advertising Research
    • Healthcare Research
    • Data Analysis
    • Top Companies
    • Latest News
No Result
View All Result
Research Snappy
No Result
View All Result

The Ultimate Beginners Guide to Linear Regression in Python. | by Bryan Dijkhuizen | The Startup | Aug, 2020

researchsnappy by researchsnappy
August 28, 2020
in Healthcare Research
0
The Ultimate Beginners Guide to Linear Regression in Python. | by Bryan Dijkhuizen | The Startup | Aug, 2020
400
SHARES
2.4k
VIEWS
Share on FacebookShare on Twitter

The term regression is used when you try to find the relationship between variables.

Bryan Dijkhuizen

By Antoine Dautry on Unsplash

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.

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.

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:

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

import matplotlib.pyplot as plt
from scipy import stats

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

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:

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:

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()

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!

Previous Post

DBX, AMC, TSLA and AAPL as Zacks Bull and Bear of the Day

Next Post

AI Spending Expected to Double Globally to $110B by 2024

Next Post
AI Spending Expected to Double Globally to $110B by 2024

AI Spending Expected to Double Globally to $110B by 2024

Research Snappy

Category

  • Advertising Research
  • Consumer Research
  • Data Analysis
  • Healthcare Research
  • Investment Research
  • News
  • Top Company News

HPIN International Financial Platform Becomes a New Benchmark for India’s Digital Economy

Top 10 Market Research Companies in the world

3 Best Market Research Certifications in High Demand

  • Privacy Policy
  • Terms of Use
  • Antispam
  • DMCA
  • Contact Us

© 2025 researchsnappy.com

No Result
View All Result
  • Market Research Forum
  • Investment Research
  • Consumer Research
  • More
    • Advertising Research
    • Healthcare Research
    • Data Analysis
    • Top Companies
    • Latest News

© 2025 researchsnappy.com