Page 182 - Touhpad Ai
P. 182

Program 6: Multi-dimensional data representation using different charts and graphs

                 # Import necessary libraries
                 import seaborn as sns

                 import matplotlib.pyplot as plt
                 import pandas as pd
                 from pandas.plotting import parallel_coordinates


                 # Load the Iris dataset

                 iris = sns.load_dataset('iris')


                 # 1. Pair Plot
                 sns.pairplot(iris, hue='species', palette='Set2')

                 plt.suptitle("Pair Plot of Iris Dataset", y=1.02)
                 plt.show()


                 # 2. Scatter Plot
                 plt.figure(figsize=(8,6))

                 sns.scatterplot(data=iris,         x='sepal_length',        y='petal_length',        hue='species',
                 style='species', s=100)

                 plt.title("Scatter Plot of Sepal Length vs Petal Length")
                 plt.show()



                 # 3. Bubble Chart
                 plt.figure(figsize=(8,6))
                 # Bubble size based on petal_width
                 sns.scatterplot(data=iris, x='sepal_length', y='petal_length', size='petal_width',
                 hue='species', sizes=(50,300), alpha=0.6, palette='Set1')
                 plt.title("Bubble Chart of Sepal Length vs Petal Length (size = Petal Width)")
                 plt.show()



                 # 4. Heatmap (Correlation Matrix)
                 plt.figure(figsize=(6,5))
                 corr = iris.iloc[:,0:4].corr()  # Only numerical features

                 sns.heatmap(corr, annot=True, cmap='coolwarm', linewidths=0.5)
                 plt.title("Heatmap of Feature Correlations")
                 plt.show()


                 # 5. Parallel Coordinates Plot

                 plt.figure(figsize=(10,6))



                180     Touchpad Artificial Intelligence - XI
   177   178   179   180   181   182   183   184   185   186   187