0% found this document useful (0 votes)
26 views

Lab 5.Ipynb - Colab

Uploaded by

ashmad928
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lab 5.Ipynb - Colab

Uploaded by

ashmad928
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

10/2/24, 3:34 PM lab 5.

ipynb - Colab

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Load Titanic dataset


titanic_data = pd.read_csv('/content/Titanic-Dataset.csv')

# Quick overview of the dataset


titanic_data.head()

PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked

Braund, Mr.
0 1 0 3 male 22.0 1 0 A/5 21171 7.2500 NaN S
Owen Harris

Cumings,
Mrs. John
1 2 1 1 Bradley female 38.0 1 0 PC 17599 71.2833 C85 C
(Florence
Briggs Th...

Heikkinen, STON/O2.
2 3 1 3 female 26.0 0 0 7.9250 NaN S
Miss. Laina 3101282

Futrelle, Mrs.
Jacques
3 4 1 1 female 35.0 1 0 113803 53.1000 C123 S
Heath (Lily
May Peel)

Next steps: Generate code with titanic_data


toggle_off View recommended plots New interactive sheet

sns.relplot(x='Age', y='Fare', data=titanic_data)


plt.show()

sns.relplot(x='Age', y='Fare', hue='Survived', data=titanic_data)


plt show()
https://colab.research.google.com/drive/12csc99WMkkrbMg4awLluSvflkT9B-Wyv#scrollTo=6P6zCJ68xKbv&printMode=true 1/6
10/2/24, 3:34 PM lab 5.ipynb - Colab
plt.show()

sns.relplot(x='Age', y='Fare', hue='Survived', style='Sex', data=titanic_data)


plt.show()

sns.relplot(x='Age', y='Fare', kind='line', data=titanic_data)


plt.show()

https://colab.research.google.com/drive/12csc99WMkkrbMg4awLluSvflkT9B-Wyv#scrollTo=6P6zCJ68xKbv&printMode=true 2/6
10/2/24, 3:34 PM lab 5.ipynb - Colab

sns.countplot(x='Pclass', data=titanic_data)
plt.show()

sns.barplot(x='Pclass', y='Fare', data=titanic_data)


plt.show()

https://colab.research.google.com/drive/12csc99WMkkrbMg4awLluSvflkT9B-Wyv#scrollTo=6P6zCJ68xKbv&printMode=true 3/6
10/2/24, 3:34 PM lab 5.ipynb - Colab

sns.boxplot(x='Pclass', y='Fare', data=titanic_data)


plt.show()

/usr/local/lib/python3.10/dist-packages/seaborn/categorical.py:640: FutureWarning: SeriesGroupBy.grouper is deprec


positions = grouped.grouper.result_index.to_numpy(dtype=float)

sns.histplot(titanic_data['Age'], kde=True)
plt.show()

https://colab.research.google.com/drive/12csc99WMkkrbMg4awLluSvflkT9B-Wyv#scrollTo=6P6zCJ68xKbv&printMode=true 4/6
10/2/24, 3:34 PM lab 5.ipynb - Colab

sns.kdeplot(titanic_data['Fare'])
plt.show()

# Selecting only numeric columns


numeric_data = titanic_data.select_dtypes(include=['float64', 'int64'])

# Calculate the correlation matrix


correlation = numeric_data.corr()

# Create a heatmap
sns.heatmap(correlation, annot=True, cmap='coolwarm')
plt.show()

https://colab.research.google.com/drive/12csc99WMkkrbMg4awLluSvflkT9B-Wyv#scrollTo=6P6zCJ68xKbv&printMode=true 5/6
10/2/24, 3:34 PM lab 5.ipynb - Colab

https://colab.research.google.com/drive/12csc99WMkkrbMg4awLluSvflkT9B-Wyv#scrollTo=6P6zCJ68xKbv&printMode=true 6/6

You might also like