w3resource

Python Scikit-learn: Create a kde plot of sepal_length versus sepal width for setosa species of flower

Python Machine learning Iris Visualization: Exercise-14 with Solution

Write a Python program using seaborn to Create a kde (Kernel Density Estimate ) plot of sepal_length versus sepal width for setosa species of flower.

Sample Solution:

Python Code:

# Import necessary modules 
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt 
iris = pd.read_csv("iris.csv")
#Drop id column
iris = iris.drop('Id',axis=1)
sub=iris[iris['Species']=='Iris-setosa']
sns.kdeplot(data=sub[['SepalLengthCm','SepalWidthCm']],cmap="plasma", shade=True, shade_lowest=False)
plt.title('Iris-setosa')
plt.xlabel('Sepal Length cm')
plt.ylabel('Sepal Width cm')
plt.show()

Output:

Python Machine learning Output: Iris Visualization: Exercise-14
 

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to create a pairplot of the iris data set and check which flower species seems to be the most separable.

Next: Write a Python program using seaborn to create a kde (Kernel Density Estimate ) plot of petal_length versus petal width for setosa species of flower.

What is the difficulty level of this exercise?