Quick Demo

Sachin Yadav, IIT Gandhinagar, sachin.yadav@iitgn.ac.in</center></h4> </div> </div> </div>

IRIS Flower data set

The data set contains information about three species of IRIS flowers namely:

  • Iris setosa
  • Iris versicolor
  • Iris virginica

Four features are collected from each sample, sepal-length, sepal-width, petal-length and petal-width in centi-meters.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

import plotly.express as px
from IPython.display import HTML
iris_df = pd.read_csv("./assets/2022-03-17-writing-assignment-cs328-demo/IRIS.csv.gz", compression="gzip")
iris_df.sample(5)
Unnamed: 0 sepal_length sepal_width petal_length petal_width species
2 2 4.7 3.2 1.3 0.2 Iris-setosa
97 97 6.2 2.9 4.3 1.3 Iris-versicolor
15 15 5.7 4.4 1.5 0.4 Iris-setosa
55 55 5.7 2.8 4.5 1.3 Iris-versicolor
16 16 5.4 3.9 1.3 0.4 Iris-setosa
fig = px.scatter_3d(iris_df, x='sepal_length', y='sepal_width', z='petal_width',
              color='species', template="plotly_dark")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
# fig.show()
HTML(fig.to_html(include_plotlyjs='cdn'))

COVID-19 Dataset

covid_df = pd.read_csv("./assets/2022-03-17-writing-assignment-cs328-demo/owid-covid-data.csv.gz", compression="gzip")
covid_df.sample(5)
Unnamed: 0 iso_code continent location date total_cases new_cases new_cases_smoothed total_deaths new_deaths ... female_smokers male_smokers handwashing_facilities hospital_beds_per_thousand life_expectancy human_development_index excess_mortality_cumulative_absolute excess_mortality_cumulative excess_mortality excess_mortality_cumulative_per_million
81661 81661 KWT Asia Kuwait 2021-01-26 162282.0 505.0 494.286 957.0 3.0 ... 2.7 37.0 NaN 2.00 75.49 0.806 NaN NaN NaN NaN
120608 120608 PCN Oceania Pitcairn 2021-07-31 NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
76010 76010 ITA Europe Italy 2021-06-07 4233698.0 1270.0 2268.143 126588.0 65.0 ... 19.8 27.8 NaN 3.18 83.51 0.892 NaN NaN NaN NaN
133771 133771 SLE Africa Sierra Leone 2021-07-18 6186.0 20.0 22.143 115.0 0.0 ... 8.8 41.3 19.275 NaN 54.70 0.452 NaN NaN NaN NaN
138065 138065 ZAF Africa South Africa 2020-11-11 742394.0 2140.0 1692.286 20011.0 60.0 ... 8.1 33.2 43.993 2.32 64.13 0.709 NaN NaN NaN NaN

5 rows × 68 columns

required_columns = ["iso_code", "location", "continent", "date", "new_cases_smoothed", "total_cases"]
covid_df = covid_df.dropna(subset = required_columns)

covid_df = covid_df.sort_values("date")
covid_df[['iso_code', 'location']].sample(8)
iso_code location
142013 LKA Sri Lanka
56774 GEO Georgia
21588 BRA Brazil
121973 PRT Portugal
147763 TZA Tanzania
147684 TZA Tanzania
54290 FRA France
98106 MEX Mexico

Covid-19 New Cases Worldwide on 23 December 2021

covid_day_df = covid_df[covid_df.date == "2021-12-23"]
covid_day_df.sample(5)
Unnamed: 0 iso_code continent location date total_cases new_cases new_cases_smoothed total_deaths new_deaths ... female_smokers male_smokers handwashing_facilities hospital_beds_per_thousand life_expectancy human_development_index excess_mortality_cumulative_absolute excess_mortality_cumulative excess_mortality excess_mortality_cumulative_per_million
6568 6568 ARG South America Argentina 2021-12-23 5428957.0 13456.0 7473.571 116979.0 15.0 ... 16.2 27.7 NaN 5.0 76.67 0.845 NaN NaN NaN NaN
73251 73251 IRQ Asia Iraq 2021-12-23 2091834.0 312.0 309.286 24108.0 13.0 ... NaN NaN 94.576 1.4 70.60 0.674 NaN NaN NaN NaN
26303 26303 KHM Asia Cambodia 2021-12-23 120434.0 4.0 5.286 3006.0 0.0 ... 2.0 33.7 66.229 0.8 69.82 0.594 NaN NaN NaN NaN
68043 68043 HKG Asia Hong Kong 2021-12-23 12550.0 2.0 6.286 213.0 0.0 ... NaN NaN NaN NaN 84.86 0.949 NaN NaN NaN NaN
100458 100458 MCO Europe Monaco 2021-12-23 4606.0 121.0 70.286 38.0 1.0 ... NaN NaN NaN 13.8 86.75 NaN NaN NaN NaN NaN

5 rows × 68 columns

fig = px.scatter_geo(covid_day_df, locations="iso_code", color="continent",
                     hover_name="location", size="new_cases_smoothed",
                     projection="natural earth", template="plotly_dark")

# fig.show()
HTML(fig.to_html(include_plotlyjs='cdn'))

Covid-19 Total Cases over the days

fig = px.scatter_geo(covid_df, locations="iso_code", color="continent",
                     hover_name="location", size="total_cases",
                     projection="natural earth", animation_frame="date", template="plotly_dark")

# fig.show()
HTML(fig.to_html(include_plotlyjs='cdn'))

MNIST Dataset

import torchvision
import os

import matplotlib.pyplot as plt
from matplotlib import rc
from matplotlib.animation import FuncAnimation
from matplotlib import animation
rc('animation', html='jshtml')

frn = 15 # Number of frames to process in the animation
fps = 1.25 # Frames per second
mywriter = animation.PillowWriter(fps=fps) 
mnist_dataset = torchvision.datasets.MNIST(root = "./assets/2022-03-17-writing-assignment-cs328-demo/mnist", train = True, download = True, transform=torchvision.transforms.ToTensor())
fig, ax = plt.subplots(figsize = (10, 10))

def change_plot(frame_idx):
    ax.cla()
    image_tensor = mnist_dataset[frame_idx][0]
    image_tensor_gray = image_tensor[0]
    image_tensor_gray = image_tensor_gray * 255
    ax.matshow(image_tensor_gray, cmap = "gray")
    for i in range(image_tensor_gray.shape[0]):
        for j in range(image_tensor_gray.shape[1]):
            ax.text(i, j, str(int(image_tensor_gray[j][i].item())), va = "center", ha = "center", color = "blue", fontsize = "small")
    ax.axis("off")
    plt.tight_layout()

anim = FuncAnimation(fig, change_plot, frn, interval=1000 / fps)
plt.close()
anim
</input>
<Figure size 432x288 with 0 Axes>
anim.save('./assets/2022-03-17-writing-assignment-cs328-demo/mnist.gif',writer=mywriter)
<Figure size 432x288 with 0 Axes>
</div>