セクション 1. 章 21
single
Visualizing Linear Regression
メニューを表示するにはスワイプしてください
The regplot (regression plot) is used to plot data and a linear regression model fit.
It draws a scatter plot of two variables, x and y, and then fits a linear regression line (best prediction line) through them to visualize the correlation.
Key Parameters
fit_reg: this is the most important switch;True(default): draws the regression line and the confidence interval (the shaded area);False: draws only the scatter plot. This is useful when you want the styling ofregplotbut don't need the model;marker: changes the symbol of the data points (e.g.,'+','x','o');color: sets the color for both the points and the line.
Example
Here is a regression plot showing the strong relationship between total bill and tip amount.
1234567891011121314151617import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('tips') # Create a regression plot sns.regplot( data=df, x='total_bill', y='tip', color='b', # Blue color marker='x', # Use 'x' as marker fit_reg=True # Show the line ) plt.show()
タスク
スワイプしてコーディングを開始
Analyze the tips dataset, but this time just visualize the raw data points using specific styling.
- Set the style to
'darkgrid'. Configure the colors by passing a dictionary: set'figure.facecolor'to'tan'and'axes.facecolor'to'cornsilk'. - Create a regplot using the
tipsdataset (df):- Map
'total_bill'toxand'tip'toy. - Set the point symbol (
marker) to'+'. - Set the
colorto'green'. - Disable the regression line by setting
fit_reg=False.
- Map
- Display the plot.
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 21
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください