Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Visualizing Linear Regression | Section
Statistical Visualization with Seaborn
セクション 1.  21
single

single

bookVisualizing 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 of regplot but 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.

1234567891011121314151617
import 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()
copy
タスク

スワイプしてコーディングを開始

Analyze the tips dataset, but this time just visualize the raw data points using specific styling.

  1. Set the style to 'darkgrid'. Configure the colors by passing a dictionary: set 'figure.facecolor' to 'tan' and 'axes.facecolor' to 'cornsilk'.
  2. Create a regplot using the tips dataset (df):
    • Map 'total_bill' to x and 'tip' to y.
    • Set the point symbol (marker) to '+'.
    • Set the color to 'green'.
    • Disable the regression line by setting fit_reg=False.
  3. Display the plot.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  21
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt