How to Perform & Plot Linear Regression in Python (in 3.5 Minutes)

Опубликовано: 11 Март 2026
на канале: JR: Educational Channel
36
4

Description:
Learn how to perform linear regression in Python in just 3.5 minutes! This quick and informative tutorial walks you through using Seaborn, scikit-learn, and Statsmodels to visualize and analyze data from the Iris dataset. You’ll learn how to fit a regression model, plot a regression line, and interpret key metrics like R-squared and p-values—all while keeping things simple and clear.

✅ What You’ll Learn:

How to create a Seaborn scatter plot with a regression line.
Fitting a linear regression model using scikit-learn's LinearRegression.
Visualizing the relationship between sepal length and petal length.
Using Statsmodels OLS to get a detailed regression summary.
Why Watch This Video?
This is a perfect tutorial for anyone learning Python for data science, covering everything from regression visualization to detailed statistical interpretation in just 3.5 minutes!

📊 Who Is This For?
This video is ideal for data science beginners, analysts, and Python enthusiasts looking to master regression analysis and improve their exploratory data analysis (EDA) skills.

🔗 Topics Covered:

How to fit a regression model in Python
Visualizing regression lines in Seaborn
Using Statsmodels OLS for statistical summaries
Calculating key metrics like coefficients, R-squared, and p-values
-------------------------------------------------------------------------------
Code from Video:
***
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
import statsmodels.api as sm

iris = sns.load_dataset('iris')

X = iris['sepal_length'].values.reshape(-1,1)
y = iris['petal_length']

model = LinearRegression()

model.fit(X,y)

sns.scatterplot(x = 'sepal_length', y='petal_length', data = iris)
plt.plot(iris['sepal_length'], model.predict(X), color = 'red')
plt.title('Linear Regression')
plt.show()
model.score(X,y)

X = iris['sepal_length']
y = iris['petal_length']

X = sm.add_constant(X)

model = sm.OLS(y,X).fit()
print(model.summary())
***