Visualize Linear Regression with Matplotlib, Pandas, and Sklearn
in just 9 lines of code!
What you will learn:
- How to make a simple linear regression model.
What you need:
- A basic understanding of Python
Recommended:
- Experience with Pandas
- An IDE of your choice
Packages
We need matplotlib.pyplot, pandas, and sklearn.linear_model for this tutorial.
pip install matplotlib
pip install pandas
pip install scikit-learnImport them into your Python file:
import matplotlib.pyplot as plt import pandas as pd from sklearn.linear_model import LinearRegressionRetrieving the dataset
You can download the dataset from here or make a file called data.csv, and copy the lines below into it.
32.502345269453031, 31.7070058465699253.426804033275019, 68.7775959816389161.530358025636438, 62.56238229794580347.475639634786098, 71.54663223356777759.813207869512318, 87.23092513368739355.142188413943821, 78.21151827079923252.211796692214001, 79.6419730498087439.299566694317065, 59.17148932186950848.10504169176825, 75.33124229706305652.550014442733818, 71.30087988685035345.419730144973755, 55.16567714595912354.351634881228918, 82.47884675749791944.164049496773352, 62.00892324572582558.16847071685779, 75.39287042599495756.727208057096611, 8.4361921588786448.955888566093719, 60.72360244067396544.687196231480904, 82.89250373145371560.297326851333466, 97.37989686216607845.618643772955828, 48.84715331735507238.816817537445637, 56.87721318626850666.189816606752601, 83.87856466460276365.41605174513407, 118.5912173025224947.48120860786787, 57.25181946226896941.57564261748702, 51.39174407983230751.84518690563943, 75.38065166531235759.370822011089523, 74.76556403215137457.31000343834809, 95.45505292257473763.615561251453308, 95.22936601755530746.737619407976972, 79.05240616956558650.556760148547767, 83.43207142132371252.223996085553047, 63.35879031749787835.567830047746632, 41.41288530370056342.436476944055642, 76.617341280074044Result:







