Page 298 - Touhpad Ai
P. 298

2.     Write a Python program using Seaborn to create a scatterplot that analyzes the relationship between two variables
                   in a dataset.
                   Download the dataset using the given link or scan the QR code:

                   https://www.kaggle.com/code/sanjanabasu/tips-dataset/input
                   import pandas as pd
                   import seaborn as sns
                   import matplotlib.pyplot as plt
                   df = pd.read_csv('D:\Data\Tips.csv')
                   sns.regplot( x='total_bill', y='tip', data=df, scatter_kws={'color': 'blue'},
                                 line_kws={'color': 'red'})
                   plt.title("Scatter Plot with Regression Line: Total Bill vs Tip")
                   plt.xlabel("Total Bill (Rs)")
                   plt.ylabel("Tip (Rs)")
                   plt.tight_layout()
                   plt.show()
                   Note: The Tips.csv  file  should  be  present  at  the  mentioned  path  on  your  computer,  otherwise,  'No  such  file  or
                   directory' will be reported.

                   Output:





























              3.     Write a Python program to utilise Matplotlib to generate a bar plot for comparing the distribution of categories in a
                   dataset.
                   Download the dataset using the given link or scan the QR code:

                   https://www.kaggle.com/datasets/yasserh/titanic-dataset
                   import pandas as pd
                   import matplotlib.pyplot as plt
                   data = pd.read_csv('D:\Data\Titanic.csv')
                   # Count the number of passengers in each class
                   class_distribution = data['Pclass'].value_counts()
                   plt.bar(class_distribution.index, class_distribution, color='lightgreen')
                   plt.title('Passenger Distribution by Class in Titanic Dataset')
                   plt.xlabel('Class')

                 296    Touchpad Artificial Intelligence - XI
   293   294   295   296   297   298   299   300   301   302   303