42 - Introduction to Seaborn Plotting in Python

preview_player
Показать описание
Seaborn is a complimentary plotting library to Matplotlib for statistical data visualization. It enhances the visualization capabilities and makes working with Pandas DataFrames easy. This tutorial covers the basics of Seaborn library and goes through a few example plots.

Рекомендации по теме
Комментарии
Автор

I've watched only a couple of your videos so far and have found them very helpful and succinct. I will be watching more in the future!

finnmccool
Автор

Quite amazing tutorial and tool this seaborn!
I've got curious about one thing. Does seaborn has a residual plot function? I mean, if I input the data, regress it, is there a possibility of it showing a plot of the residual values?

felip
Автор

ChatGPT told me that seaborn doesn't provide the underlying equation for lmplot - there is an indirect way to find that out - but your way is easier !

import seaborn as sns
import statsmodels.formula.api as smf

# Generate a scatter plot with a regression line using lmplot
sns.set(style="ticks")
tips = sns.load_dataset("tips")
lm = sns.lmplot(x="total_bill", y="tip", data=tips)

# Extract the data from the lmplot figure
x_data = lm.ax.collections[0].get_offsets()[:, 0]
y_data = lm.ax.collections[0].get_offsets()[:, 1]

# Fit a linear regression model using statsmodels
model = smf.ols(formula='y ~ x', data=pd.DataFrame({'x': x_data, 'y': y_data})).fit()

# Extract the coefficients from the model
intercept = model.params['Intercept']
slope = model.params['x']

# Build the equation
equation = f"y = {slope:.2f} * x + {intercept:.2f}"
print(equation)

chrisphayao