62 KiB
62 KiB
%matplotlib inline
%load_ext autoreload
%autoreload 2
import numpy as np
import pandas as pd
import torch
import matplotlib.pyplot as plt
import seaborn as sns
from IPython.display import Markdown, display, HTML
# Fix the dying kernel problem (only a problem in some installations - you can remove it, if it works without it)
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
a = np.array(
[[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0]]
)
print("Numpy array")
print(a)
print()
df = pd.DataFrame(a, columns=['A', 'B', 'C'])
print("Pandas DataFrame")
print(df)
print()
print("Pretty display of pandas DataFrame")
display(HTML(df.to_html(index=False)))
print()
tensor = torch.from_numpy(a)
print("PyTorch tensor")
print(tensor)
print()
# Matplotlib
print("Matplolib chart")
# Prepare the data
x = np.linspace(0, 10, 100)
# Plot the data
plt.plot(x, x, label='linear')
# Add a legend
plt.legend()
# Show the plot
plt.show()
# Seaborn
print("Seaborn chart")
sns.set_theme(style="darkgrid")
# Load the example Titanic dataset (the dataset may load some time)
df = sns.load_dataset("titanic")
# Make a custom palette with gendered colors
pal = dict(male="#6495ED", female="#F08080")
# Show the survival probability as a function of age and sex
g = sns.lmplot(x="age", y="survived", col="sex", hue="sex", data=df,
palette=pal, y_jitter=.02, logistic=True, truncate=False)
g.set(xlim=(0, 80), ylim=(-.05, 1.05))
# Show the plot
plt.show()
Numpy array [[1. 2. 3.] [4. 5. 6.] [7. 8. 9.]] Pandas DataFrame A B C 0 1.0 2.0 3.0 1 4.0 5.0 6.0 2 7.0 8.0 9.0 Pretty display of pandas DataFrame
A | B | C |
---|---|---|
1.0 | 2.0 | 3.0 |
4.0 | 5.0 | 6.0 |
7.0 | 8.0 | 9.0 |
PyTorch tensor tensor([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]], dtype=torch.float64) Matplolib chart
Seaborn chart