To Perform Data Visualization on a complex dataset and save the data to a file.
Data visualization is the graphical representation of information and data. By using visual elements like charts, graphs, and maps, data visualization tools provide an accessible way to see and understand trends, outliers, and patterns in data.
Read the given Data
Clean the Data Set using Data Cleaning Process
Apply Feature generation and selection techniques to all the features of the data set
Apply data visualization techniques to identify the patterns of the data.
Name: Aaron Dominic
Reg : 212221040001
import seaborn as sns
import matplotlib.pyplot as plt
# Load the tips dataset
tips = sns.load_dataset('tips')
# Drop rows with all missing values
tips.dropna(how='all', inplace=True)
sns.barplot(x='day', y='total_bill', data=tips)
plt.show()
# a) Which day of the week has the highest total bill amount?
# Group by day and sum total_bill
total_bill_by_day = tips.groupby('day')['total_bill'].sum()
# Sort by descending order and select the first row
highest_total_bill_day = total_bill_by_day.sort_values(ascending=False).index[0]
print("The day with the highest total bill amount is:", highest_total_bill_day)
# b) What is the average tip amount given by smokers and non-smokers?
sns.barplot(x='smoker', y='tip', data=tips)
plt.show()
# Group by smoker and calculate mean of tip
tip_by_smoker = tips.groupby('smoker')['tip'].mean()
print("Average tip amount given by smokers:", tip_by_smoker['Yes'])
print("Average tip amount given by non-smokers:", tip_by_smoker['No'])
# c) How does the tip percentage vary based on the size of the dining party?
tips['tip_percentage'] = tips['tip'] / tips['total_bill'] * 100
sns.pointplot(x='size', y='tip_percentage', data=tips)
plt.show()
# Create a new column for tip percentage
tips['tip_percentage'] = tips['tip'] / tips['total_bill']
# Group by size and calculate mean of tip percentage
tip_percentage_by_size = tips.groupby('size')['tip_percentage'].mean()
print("Tip percentage by size of dining party:")
print(tip_percentage_by_size)
# d) Which gender tends to leave higher tips?
sns.boxplot(x='sex', y='tip', data=tips)
plt.show()
# Group by gender and calculate mean of tip
tip_by_gender = tips.groupby('sex')['tip'].mean()
print("Average tip amount by gender:")
print(tip_by_gender)
# e) Is there any relationship between the total bill amount and the day of the week?
sns.scatterplot(x='total_bill', y='day', data=tips)
plt.show()
# f) How does the distribution of total bill amounts vary across different time periods (lunch vs. dinner)?
sns.boxplot(x='time', y='total_bill', data=tips)
plt.show()
# g) Which dining party size group tends to have the highest average total bill amount?
sns.barplot(x='size', y='total_bill', data=tips)
plt.show()
# Group by size and calculate mean of total_bill
total_bill_by_size = tips.groupby('size')['total_bill'].mean()
print("Average total bill amount by size of dining party:")
print(total_bill_by_size)
# h) What is the distribution of tip amounts for each day of the week?
sns.boxplot(x='day', y='tip', data=tips)
plt.show()
# i) How does the tip amount vary based on the type of service (lunch vs. dinner)?
sns.boxplot(x='time', y='tip', data=tips)
plt.show()
# j) Is there any correlation between the total bill amount and the tip amount?
sns.scatterplot(x='total_bill', y='tip', data=tips)
plt.show()
correlation = tips['total_bill'].corr(tips['tip'])
print("Correlation coefficient between total_bill and tip:", correlation)
Thus, Data Visualization on a complex dataset and save the data to a file has been performed successfully.