セクション 1. 章 5
single
Estimating Density with KDE
メニューを表示するにはスワイプしてください
A kdeplot (kernel density estimation) is a method for visualizing the distribution of observations in a dataset. It is analogous to a histogram, but instead of using discrete bins, KDE represents the data using a continuous probability density curve.
This makes it excellent for seeing the "shape" of data and identifying peaks without the jaggedness of a histogram.
Visualizing Overlapping Distributions
When you have multiple categories (using hue), simple lines can become hard to distinguish. Seaborn offers parameters to fix this:
- Stacking (
multiple='stack'): instead of plotting lines over each other, this stacks them. It shows how different categories contribute to the total distribution; - Filling (
fill=True): fills the area under the curve with color, making the visual weight of each category more apparent.
Example:
12345678910111213141516import seaborn as sns import matplotlib.pyplot as plt # Load built-in dataset df = sns.load_dataset('penguins') # Create the stacked KDE plot sns.kdeplot( data=df, x='flipper_length_mm', hue='species', multiple='stack', # Stack categories vertically fill=True # Fill area with color ) plt.show()
タスク
スワイプしてコーディングを開始
Visualize the distribution of maximum temperatures throughout the year:
- Import
pandas,seaborn, andmatplotlib.pyplot. - Read the weather dataset.
- Set the style to
'ticks'with a'lightcyan'background color (already provided). - Create a KDE plot with the following parameters:
- Set
xto'max_temp'; - Group by
'month'usinghue; - Stack the distributions using
multiple='stack'; - Fill the curves using
fill=True; - Disable the legend (
legend=False) to avoid cluttering the plot.
- Set
- Display the plot.
解答
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 5
single
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください