Zajęcia 7 z Sacred (Zadanie 2 nie jest skończone - awaria Jenkinsa)

This commit is contained in:
Dominik Strzako 2021-05-09 23:34:32 +02:00
parent fcc6e77ef0
commit a325b2ca80
15 changed files with 1546 additions and 0 deletions

View File

@ -13,6 +13,7 @@ RUN pip3 install --user pandas
RUN pip3 install --user numpy
RUN pip3 install --user matplotlib
RUN pip3 install --user tensorflow
RUN pip3 install --user sacred
# Stwórzmy w kontenerze (jeśli nie istnieje) katalog /app i przejdźmy do niego (wszystkie kolejne polecenia RUN, CMD, ENTRYPOINT, COPY i ADD będą w nim wykonywane)

View File

@ -13,6 +13,7 @@ RUN pip3 install --user pandas
RUN pip3 install --user numpy
RUN pip3 install --user matplotlib
RUN pip3 install --user tensorflow
RUN pip3 install --user sacred
# Stwórzmy w kontenerze (jeśli nie istnieje) katalog /app i przejdźmy do niego (wszystkie kolejne polecenia RUN, CMD, ENTRYPOINT, COPY i ADD będą w nim wykonywane)

View File

@ -0,0 +1,76 @@
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 FileStorageObserver
from sacred import Experiment
from datetime import datetime
import os
ex = Experiment("file_observer", interactive=True)
ex.observers.append(FileStorageObserver('Zajęcia7/my_runs'))
@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")

View File

@ -0,0 +1,84 @@
'''
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")

View File

@ -0,0 +1,5 @@
{
"seed": 93742377,
"test_size_param": 0.2,
"train_size_param": 0.8
}

1216
Zajęcia7/my_runs/1/cout.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,4 @@
{
"Final Results: ": " precision recall f1-score support\n\n 3 0.00 0.00 0.00 1\n 4 0.00 0.00 0.00 16\n 5 0.69 0.65 0.67 127\n 6 0.58 0.69 0.63 131\n 7 0.56 0.52 0.54 42\n 8 0.00 0.00 0.00 3\n\n accuracy 0.61 320\n macro avg 0.30 0.31 0.31 320\nweighted avg 0.58 0.61 0.60 320\n",
"prepare_model_ts": "2021-05-09 23:25:48.528529"
}

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,82 @@
{
"artifacts": [
"saved_model.pb"
],
"command": "my_main",
"experiment": {
"base_dir": "c:\\Users\\domstr2\\Desktop\\Git Repositories\\ium_434788\\Zaj\u0119cia7",
"dependencies": [
"numpy==1.19.2",
"pandas==1.1.3",
"sacred==0.8.2",
"scikit-learn==0.23.2",
"tensorflow==2.4.1",
"wget==3.2"
],
"mainfile": "Zadanie_1_Sacred.py",
"name": "file_observer",
"repositories": [
{
"commit": "fcc6e77ef0297c583ccde2a4eb5924839a8f2f09",
"dirty": true,
"url": "https://git.wmi.amu.edu.pl/s434788/ium_434788.git"
}
],
"sources": [
[
"Zadanie_1_Sacred.py",
"_sources\\Zadanie_1_Sacred_30ef87dbd210931ef4b8384e66e7736f.py"
]
]
},
"heartbeat": "2021-05-09T21:26:06.005402",
"host": {
"ENV": {},
"cpu": "Unknown",
"gpus": {
"driver_version": "465.89",
"gpus": [
{
"model": "NVIDIA GeForce GTX 970",
"persistence_mode": false,
"total_memory": 4096
}
]
},
"hostname": "DESKTOP-1NBQAAH",
"os": [
"Windows",
"Windows-10-10.0.19041-SP0"
],
"python_version": "3.8.5"
},
"meta": {
"command": "my_main",
"options": {
"--beat-interval": null,
"--capture": null,
"--comment": null,
"--debug": false,
"--enforce_clean": false,
"--file_storage": null,
"--force": false,
"--help": false,
"--loglevel": null,
"--mongo_db": null,
"--name": null,
"--pdb": false,
"--print-config": false,
"--priority": null,
"--queue": false,
"--s3": null,
"--sql": null,
"--tiny_db": null,
"--unobserved": false
}
},
"resources": [],
"result": null,
"start_time": "2021-05-09T21:25:48.516529",
"status": "COMPLETED",
"stop_time": "2021-05-09T21:26:06.004401"
}

Binary file not shown.

View File

@ -0,0 +1,76 @@
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 FileStorageObserver
from sacred import Experiment
from datetime import datetime
import os
ex = Experiment("file_observer", interactive=True)
ex.observers.append(FileStorageObserver('Zajęcia7/my_runs'))
@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")

Binary file not shown.

Binary file not shown.