ium_s487182/create_dataset.py

63 lines
2.2 KiB
Python
Raw Normal View History

2023-04-14 03:14:42 +02:00
2023-04-15 05:03:38 +02:00
#Downloading DataSet from kaggle - Replaced by Jenkins
#from kaggle.api.kaggle_api_extended import KaggleApi
#api = KaggleApi()
#api.authenticate()
#api.dataset_download_file('mssmartypants/water-quality', file_name='waterQuality1.csv')
2023-04-14 03:14:42 +02:00
2023-04-19 19:17:56 +02:00
import argparse
parser = argparse.ArgumentParser(description='Program for Downloading Dataset from Kaggle and Normalisation')
parser.add_argument('CUT', type=int, nargs='?', default=7999, help='Cut this number of rows from csv file')
args = parser.parse_args()
2023-04-17 21:28:02 +02:00
2023-04-14 03:14:42 +02:00
#Reading DataSet from csv using pandas library
import pandas as pd
2023-04-18 21:40:52 +02:00
water = pd.read_csv('waterQuality1.csv', nrows = args.CUT)
2023-04-17 21:28:02 +02:00
2023-04-14 03:14:42 +02:00
#water.describe(include='all')
# Clearing DataSet from non digit values in is_safe column
water = water[water['is_safe'].apply(lambda x: str(x).isdigit())]
water['is_safe'].value_counts()
2023-06-16 01:38:25 +02:00
# Normalizing Dataset to [0.0, 1.0] float values
from sklearn import preprocessing
water_min_max = preprocessing.MinMaxScaler()
water_min_max = water_min_max.fit_transform(water)
water_min_max = pd.DataFrame(water_min_max, columns=water.columns)
waterNorm = water_min_max
2023-04-14 03:14:42 +02:00
# Splitting DataSet on train, dev, test parts
from sklearn.model_selection import train_test_split
2023-06-16 01:38:25 +02:00
water_train, water_test = train_test_split(waterNorm, train_size=0.8, random_state=1, stratify=waterNorm["is_safe"])
2023-04-14 03:14:42 +02:00
water_test, water_dev = train_test_split(water_test, train_size=0.66, random_state=1, stratify=water_test["is_safe"])
2023-04-19 19:05:41 +02:00
# water_train["is_safe"].value_counts()
# water_test["is_safe"].value_counts()
# water_dev["is_safe"].value_counts()
2023-04-14 03:14:42 +02:00
2023-04-19 19:05:41 +02:00
# print(f'''
# Statystyki zbioru:
# Wielkość zbioru - {len(water)}
# Wielkość podzbioru treningowego - {len(water_train)}
# Wielkość podzbioru walidującego - {len(water_dev)}
# Wielkość podzbioru testowego - {len(water_test)}
2023-04-14 03:14:42 +02:00
2023-04-19 19:05:41 +02:00
# Rozkład częstości parametru mówiącemu o zdantości picia wody (0 oznacza zdanty do picia):
# ''')
2023-04-14 03:14:42 +02:00
#water["is_safe"].value_counts().plot(kind="bar")
2023-06-16 01:40:48 +02:00
import os
2023-06-16 01:39:44 +02:00
directory ='dane'
if not os.path.exists(directory):
os.makedirs('dane')
2023-04-19 20:19:55 +02:00
waterNorm.to_csv('waterQuality.csv', index=False)
2023-06-16 01:42:44 +02:00
water_train.to_csv('dane/water_train.csv', index=False)
water_test.to_csv('dane/water_test.csv', index=False)
water_dev.to_csv('dane/water_dev.csv', index=False)
2023-04-14 03:14:42 +02:00