ium_434804/stats.py
Dawid 4aae76c38b
Some checks failed
s434804-training/pipeline/head This commit looks good
s434804-evaluation/pipeline/head There was a failure building this commit
change creating datasets
2021-05-14 22:48:23 +02:00

39 lines
1.5 KiB
Python

import zipfile
import numpy as np
import pandas as pd
import wget
from sklearn import preprocessing
url = 'https://git.wmi.amu.edu.pl/s434804/ium_434804/raw/branch/master/country_vaccinations.csv'
wget.download(url, out='country_vaccinations.csv', bar=None)
df = pd.read_csv('country_vaccinations.csv')
# podział danych na train/validate/test (6:2:2) za pomocą biblioteki numpy i pandas
train, validate, test = np.split(df.sample(frac=1), [int(.6*len(df)), int(.8*len(df))])
train.to_csv("train.csv")
validate.to_csv("validate.csv")
test.to_csv("test.csv")
# Wypisanie ilości elementów w poszczególnych ramkach danych
print("Whole set size".ljust(20), df.size)
print("Train set size: ".ljust(20), train.size)
print("Validate set size: ".ljust(20), validate.size)
print("Test set size: ".ljust(20), test.size)
df.describe(include='all')
for col in df.columns:
column = df[col].value_counts().plot(kind="bar",figsize=(30,10))
print("\n", col)
print(column)
# normalizacja wartości numerycznych
numeric_values = df.select_dtypes(include='float64').values # tylko wartości numeryczne
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(numeric_values)
numeric_columns = df.select_dtypes(include='float64').columns
df_normalized = pd.DataFrame(x_scaled, columns=numeric_columns)
for col in df.columns: # usunięcie nieznormalizowanych danych i wstawienie nowych już znormalizowanych do oryginalnej ramki danych
if col in numeric_columns: df[col] = df_normalized[col]
df.dropna() # usunięcie wierszy z polami NaN