From 31dfaf28c8848a2e795aece265be62be17a4ad43 Mon Sep 17 00:00:00 2001 From: s434695 Date: Sun, 25 Apr 2021 23:24:46 +0200 Subject: [PATCH] zadanie 5 --- Dockerfile | 6 ++++- dataset_stats/Jenkinsfile | 4 +-- zadanie5.py | 51 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100755 zadanie5.py diff --git a/Dockerfile b/Dockerfile index 81fa718..c98c22a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,13 +7,17 @@ RUN apt install -y git RUN apt install -y python3-pip RUN pip3 install --user kaggle RUN pip3 install --user pandas +RUN pip3 install --user numpy RUN pip3 install --user seaborn RUN pip3 install --user sklearn RUN pip3 install --user matplotlib +RUN pip3 install --user tensorflow WORKDIR /app COPY ./skrypt.sh ./ COPY ./zadanie2.py ./ +COPY ./zadanie5.py ./ -CMD ./zadanie2.py \ No newline at end of file +CMD ./zadanie2.py +CMD ./zadanie5.py diff --git a/dataset_stats/Jenkinsfile b/dataset_stats/Jenkinsfile index 788d92d..a901ffb 100644 --- a/dataset_stats/Jenkinsfile +++ b/dataset_stats/Jenkinsfile @@ -1,6 +1,6 @@ pipeline { agent { - docker { image 'shroomy/ium:1' } + docker { image 'shroomy/ium:2' } } parameters { buildSelector(defaultSelector: @@ -31,4 +31,4 @@ pipeline { } } -} \ No newline at end of file +} diff --git a/zadanie5.py b/zadanie5.py new file mode 100755 index 0000000..c3d8e5b --- /dev/null +++ b/zadanie5.py @@ -0,0 +1,51 @@ +#! /usr/bin/python3 +from tensorflow.keras.models import Sequential, load_model +from tensorflow.keras.layers import Dense +from sklearn.metrics import accuracy_score, classification_report +import pandas as pd +from sklearn.model_selection import train_test_split +import numpy as np +import requests +url = 'https://git.wmi.amu.edu.pl/s434695/ium_434695/raw/commit/2301fb86e434734376f73503307a8f3255a75cc6/vgsales.csv' +r = requests.get(url, allow_redirects=True) + +open('vgsales.csv', 'wb').write(r.content) +df = pd.read_csv('vgsales.csv') + + + +def regression_model(): + model = Sequential() + model.add(Dense(32,activation = "relu", input_shape = (x_train.shape[1],))) + model.add(Dense(64,activation = "relu")) + model.add(Dense(1,activation = "relu")) + + model.compile(optimizer = "adam", loss = "mean_squared_error") + return model + +df['Nintendo'] = df['Publisher'].apply(lambda x: 1 if x=='Nintendo' else 0) +df = df.drop(['Rank','Name','Platform','Year','Genre','Publisher'],axis = 1) +df + +y = df.Nintendo + +df=((df-df.min())/(df.max()-df.min())) + +x = df.drop(['Nintendo'],axis = 1) + +x_train, x_test, y_train, y_test = train_test_split(x,y , test_size=0.2,train_size=0.8, random_state=21) + +model = regression_model() +model.fit(x_train, y_train, epochs = 600, verbose = 1) + +y_pred = model.predict(x_test) + +y_pred[:5] + +y_pred = np.around(y_pred, decimals=0) + +y_pred[:5] + +print(accuracy_score(y_test, y_pred)) + +print(classification_report(y_test,y_pred))