diff --git a/lab5/create/Dockerfile b/lab5/create/Dockerfile new file mode 100644 index 0000000..f3598ed --- /dev/null +++ b/lab5/create/Dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:latest + +RUN apt update >>/dev/null +RUN apt install -y apt-utils >>/dev/null +RUN apt install -y python3.8 >>/dev/null +RUN apt install -y python3-pip >>/dev/null +RUN apt install -y unzip >>/dev/null + +WORKDIR /app + +COPY ./test_eval.py ./ +COPY ./script.sh ./ +RUN chmod +x script.sh + +COPY ./requirements.txt ./ + +RUN pip3 install -r requirements.txt >>/dev/null + +CMD ./script.sh diff --git a/lab5/create_dataset.py b/lab5/create/create_dataset.py similarity index 100% rename from lab5/create_dataset.py rename to lab5/create/create_dataset.py diff --git a/lab5/create/requirements.txt b/lab5/create/requirements.txt new file mode 100644 index 0000000..55679cf --- /dev/null +++ b/lab5/create/requirements.txt @@ -0,0 +1,3 @@ +kaggle +pandas +sklearn diff --git a/lab5/create/script.sh b/lab5/create/script.sh new file mode 100644 index 0000000..70e2327 --- /dev/null +++ b/lab5/create/script.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +kaggle datasets download -d 'pcbreviglieri/smart-grid-stability' +unzip smart-grid-stability.zip >>/dev/null 2>&1 + +python3 create_dataset.py diff --git a/lab5/eval/Dockerfile b/lab5/eval/Dockerfile new file mode 100644 index 0000000..f3598ed --- /dev/null +++ b/lab5/eval/Dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:latest + +RUN apt update >>/dev/null +RUN apt install -y apt-utils >>/dev/null +RUN apt install -y python3.8 >>/dev/null +RUN apt install -y python3-pip >>/dev/null +RUN apt install -y unzip >>/dev/null + +WORKDIR /app + +COPY ./test_eval.py ./ +COPY ./script.sh ./ +RUN chmod +x script.sh + +COPY ./requirements.txt ./ + +RUN pip3 install -r requirements.txt >>/dev/null + +CMD ./script.sh diff --git a/lab5/eval.py b/lab5/eval/eval.py similarity index 100% rename from lab5/eval.py rename to lab5/eval/eval.py diff --git a/lab5/eval/requirements.txt b/lab5/eval/requirements.txt new file mode 100644 index 0000000..fe0488e --- /dev/null +++ b/lab5/eval/requirements.txt @@ -0,0 +1,3 @@ +numpy~=1.19.2 +pandas +tensorflow diff --git a/lab5/eval/script.sh b/lab5/eval/script.sh new file mode 100644 index 0000000..852290d --- /dev/null +++ b/lab5/eval/script.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python3 eval.py diff --git a/lab5/test_eval.py b/lab5/test_eval.py deleted file mode 100644 index 2b95daa..0000000 --- a/lab5/test_eval.py +++ /dev/null @@ -1,61 +0,0 @@ -import numpy as np -import pandas as pd -import tensorflow as tf - -from sklearn import preprocessing -from sklearn.model_selection import train_test_split -from tensorflow.keras import layers - - -def onezero(label): - return 0 if label == 'unstable' else 1 - - -df = pd.read_csv('smart_grid_stability_augmented.csv') - -scaler = preprocessing.StandardScaler().fit(df.iloc[:, 0:-1]) -df_norm_array = scaler.transform(df.iloc[:, 0:-1]) -df_norm = pd.DataFrame(data=df_norm_array, - columns=df.columns[:-1]) -df_norm['stabf'] = df['stabf'] - -df_norm_data = df_norm.copy() -df_norm_data = df_norm_data.drop('stab', axis=1) -df_norm_labels = df_norm_data.pop('stabf') - -X_train, X_testAndValid, Y_train, Y_testAndValid = train_test_split( - df_norm_data, - df_norm_labels, - test_size=0.2, - random_state=42) - -X_test, X_valid, Y_test, Y_valid = train_test_split( - X_testAndValid, - Y_testAndValid, - test_size=0.5, - random_state=42) - -model = tf.keras.Sequential([ - layers.Input(shape=(12,)), - layers.Dense(32), - layers.Dense(16), - layers.Dense(2, activation='softmax') - ]) - -model.compile( - loss=tf.losses.BinaryCrossentropy(), - optimizer=tf.optimizers.Adam(), - metrics=[tf.keras.metrics.BinaryAccuracy()]) - -Y_train_one_zero = [onezero(x) for x in Y_train] -Y_train_onehot = np.eye(2)[Y_train_one_zero] - -Y_test_one_zero = [onezero(x) for x in Y_test] -Y_test_onehot = np.eye(2)[Y_test_one_zero] - -history = model.fit(tf.convert_to_tensor(X_train, np.float32), Y_train_onehot, epochs=5) - -results = model.evaluate(X_test, Y_test_onehot, batch_size=64) -f = open('model_eval.txt', 'w') -f.write('test loss: ' + str(results[0]) + '\n' + 'test acc: ' + str(results[1])) -f.close() diff --git a/lab5/train/Dockerfile b/lab5/train/Dockerfile new file mode 100644 index 0000000..f3598ed --- /dev/null +++ b/lab5/train/Dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:latest + +RUN apt update >>/dev/null +RUN apt install -y apt-utils >>/dev/null +RUN apt install -y python3.8 >>/dev/null +RUN apt install -y python3-pip >>/dev/null +RUN apt install -y unzip >>/dev/null + +WORKDIR /app + +COPY ./test_eval.py ./ +COPY ./script.sh ./ +RUN chmod +x script.sh + +COPY ./requirements.txt ./ + +RUN pip3 install -r requirements.txt >>/dev/null + +CMD ./script.sh diff --git a/lab5/train/requirements.txt b/lab5/train/requirements.txt new file mode 100644 index 0000000..fe0488e --- /dev/null +++ b/lab5/train/requirements.txt @@ -0,0 +1,3 @@ +numpy~=1.19.2 +pandas +tensorflow diff --git a/lab5/train/script.sh b/lab5/train/script.sh new file mode 100644 index 0000000..e6d2d51 --- /dev/null +++ b/lab5/train/script.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python3 train.py diff --git a/lab5/train.py b/lab5/train/train.py similarity index 100% rename from lab5/train.py rename to lab5/train/train.py