Skip to content

Instantly share code, notes, and snippets.

View mpatacchiola's full-sized avatar
:octocat:
...

Massimiliano Patacchiola mpatacchiola

:octocat:
...
View GitHub Profile
@mpatacchiola
mpatacchiola / gmm.py
Last active November 10, 2020 19:51
Implementation of a Gaussian Mixture Model (GMM) for the bdims dataset. It plots the negative log-likelihood, distribution over data, and the fitted curves. The number of GMM components can be changed.
import numpy as np
from scipy.stats import norm
import scipy.stats as stats
import matplotlib.pyplot as plt
import matplotlib
def plot_distributions(data, data_sampled, mu, sigma, K, color="green", color_sampled="red", name='plot.png'):
matplotlib.rcParams['text.usetex'] = True
plt.rcParams.update({'font.size': 16})
data_sampled = np.clip(data_sampled, np.min(data), np.max(data))
@mpatacchiola
mpatacchiola / bdims.csv
Last active July 28, 2020 17:25
Body girth measurements and skeletal diameter measurements, as well as age, weight, height and gender, are given for 507 physically active individuals - 247 men and 260 women. These data can be used to provide statistics students practice in the art of data analysis. Such analyses range from simple descriptive displays to more complicated multiv…
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 25 columns, instead of 5. in line 8.
"bia_di","bii_di","bit_di","che_de","che_di","elb_di","wri_di","kne_di","ank_di","sho_gi","che_gi","wai_gi","nav_gi","hip_gi","thi_gi","bic_gi","for_gi","kne_gi","cal_gi","ank_gi","wri_gi","age","wgt","hgt","sex"
42.9,26,31.5,17.7,28,13.1,10.4,18.8,14.1,106.2,89.5,71.5,74.5,93.5,51.5,32.5,26,34.5,36.5,23.5,16.5,21,65.6,174,1
43.7,28.5,33.5,16.9,30.8,14,11.8,20.6,15.1,110.5,97,79,86.5,94.8,51.5,34.4,28,36.5,37.5,24.5,17,23,71.8,175.3,1
40.1,28.2,33.3,20.9,31.7,13.9,10.9,19.7,14.1,115.1,97.5,83.2,82.9,95,57.3,33.4,28.8,37,37.3,21.9,16.9,28,80.7,193.5,1
44.3,29.9,34,18.4,28.2,13.9,11.2,20.9,15,104.5,97,77.8,78.8,94,53,31,26.2,37,34.8,23,16.6,23,72.6,186.5,1
42.5,29.9,34,21.5,29.4,15.2,11.6,20.7,14.9,107.5,97.5,80,82.5,98.5,55.4,32,28.4,37.7,38.6,24.4,18,22,78.8,187.2,1
43.3,27,31.5,19.6,31.3,14,11.5,18.8,13.9,119.8,99.9,82.5,80.1,95.3,57.5,33,28,36.6,36.1,23.5,16.9,21,74.8,181.5,1
43.5,30,34,21.9,31.7,16.1,12.5,20.8,15.6,123.5,106.9,82,84,101,60.9,42.4,32.3,40.1,40.3,23.6,18.8,26,86.4,184,1
44.4,29.8,33.2,21.8,2
@mpatacchiola
mpatacchiola / tinyimagenet_validation_preprocessing.py
Last active June 28, 2019 09:47
This script moves the images from the `val/images` folder to the `val/class_id` folder. This is useful if you want to load the dataset with torchvision ImageFolder class. Run the script from the `tiny-imagenet-200` folder. The dataset can be downloaded from https://tiny-imagenet.herokuapp.com
import shutil
import os
for i, line in enumerate(map(lambda s: s.strip(), open("./val/val_annotations.txt"))):
name, wnid = line.split("\t")[0:2]
origin_path_file = "./val/images/" + name
destination_path = "./val/" + wnid
destination_path_file = "./val/" + wnid + "/" + name
if not os.path.exists(destination_path): os.makedirs(destination_path)
shutil.move(origin_path_file, destination_path_file)