-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelative Frequency Analysis.py
More file actions
48 lines (36 loc) · 1.24 KB
/
Relative Frequency Analysis.py
File metadata and controls
48 lines (36 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
"""Welcome to Colab
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/notebooks/intro.ipynb
"""
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# first Qualitative
# use Titanic from seaborn
titanic = sns.load_dataset("titanic")
# relative frequency
freq = titanic["sex"].value_counts(normalize=True)
print(freq)
# Bar graph
freq.plot(kind="bar", title="Relative Frequency - Sex")
plt.show()
# Pie chart
freq.plot(kind="pie", autopct="%.2f%%", title="Relative Frequency - Sex")
plt.ylabel("")
plt.show()
# Second Quantitative
iris = sns.load_dataset("iris")
# Cumulative frequency graph (petal_length)
iris["petal_length"].sort_values().reset_index(drop=True).plot(drawstyle="steps-post", title="Cumulative Frequency - Petal Length")
plt.show()
# Cumulative relative frequency
iris["petal_length"].sort_values().reset_index(drop=True).div(len(iris)).plot(drawstyle="steps-post", title="Cumulative Relative Frequency - Petal Length")
plt.show()
# Scatter plot (petal_length vs petal_width)
plt.scatter(iris["petal_length"], iris["petal_width"])
plt.xlabel("Petal Length")
plt.ylabel("Petal Width")
plt.title("Scatter Plot - Petal Length vs Width")
plt.show()