''' Zadanie na dzień 09.05.2021 nie jest możliwe do skończenia bez dostępu do Jenkinsa! ''' 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 wget import numpy as np from sacred.observers import MongoObserver from sacred import Experiment from datetime import datetime import os ex = Experiment("sacred_scopes", interactive=True) ex.observers.append(MongoObserver(url='mongodb://mongo_user:mongo_password_IUM_2021@localhost:27017', db_name='sacred')) # Tutaj podajemy dane uwierzytelniające i nazwę bazy skonfigurowane w pliku .env podczas uruchamiania bazy. # W przypadku instancji na Jenkinsie url będzie wyglądał następująco: mongodb://mongo_user:mongo_password_IUM_2021@localhost:27017 @ex.config def my_config(): train_size_param = 0.8 test_size_param = 0.2 @ex.capture def prepare_model(train_size_param, test_size_param, _run): _run.info["prepare_model_ts"] = str(datetime.now()) url = 'https://git.wmi.amu.edu.pl/s434788/ium_434788/raw/branch/master/winequality-red.csv' wget.download(url, out='Zajęcia7/winequality-red.csv', bar=None) wine=pd.read_csv('Zajęcia7/winequality-red.csv') wine y = wine.quality y.head() x = wine.drop(['quality'], axis= 1) x.head() x=((x-x.min())/(x.max()-x.min())) #Normalizacja x_train, x_test, y_train, y_test = train_test_split(x,y , test_size=test_size_param, train_size=train_size_param, random_state=21) 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 model = regression_model() model.fit(x_train, y_train, epochs = 600, verbose = 1) model.save('Zajęcia7/saved_model') 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)) _run.info["Final Results: "] = classification_report(y_test,y_pred) return(classification_report(y_test,y_pred)) @ex.main def my_main(train_size_param, test_size_param): print(prepare_model()) ## Nie musimy przekazywać wartości r = ex.run() ex.add_artifact("Zajęcia7/saved_model/saved_model.pb")