mlflow attempt task 2

This commit is contained in:
Kamila 2022-05-15 11:05:21 +02:00
parent 0879e7ed2a
commit b79af25c61
2 changed files with 25 additions and 5 deletions

View File

@ -1,6 +1,7 @@
pipeline { pipeline {
agent { agent {
dockerfile true dockerfile true
args '-v /mlruns:/mlruns'
} }
parameters { parameters {
@ -30,7 +31,6 @@ pipeline {
"KAGGLE_KEY=${params.KAGGLE_KEY}"]) { "KAGGLE_KEY=${params.KAGGLE_KEY}"]) {
sh 'python3 ./nn_train_mlflow.py' sh 'python3 ./nn_train_mlflow.py'
archiveArtifacts artifacts: 'mlruns/**' archiveArtifacts artifacts: 'mlruns/**'
sh 'rm -r mlruns'
sh 'rm -r my_model_mlflow' sh 'rm -r my_model_mlflow'
} }
} }

View File

@ -9,8 +9,11 @@ from keras.utils import np_utils
from tensorflow import keras from tensorflow import keras
import mlflow import mlflow
import sys import sys
from urllib.parse import urlparse
mlflow.set_experiment("s444517") mlflow.set_experiment("s444517")
mlflow.set_tracking_uri("http://172.17.0.1:5000")
# reading data # reading data
def read_data(): def read_data():
@ -79,10 +82,27 @@ with mlflow.start_run():
y_true.append(sorted(y_class_names)[np.argmax(single_pred)]) y_true.append(sorted(y_class_names)[np.argmax(single_pred)])
y_pred.append(y_test_set[numerator]) y_pred.append(y_test_set[numerator])
signature = mlflow.models.signature.infer_signature(x_train_set, model.predict(x_train_set))
input_example = {
"Rating": 4.100000,
"Reviews": 0.000001,
"Installs": 0.000005,
"Price": 0.000000,
"Genres_numeric_value": 57.000000
}
mlflow.log_param("epoch", epoch) mlflow.log_param("epoch", epoch)
mlflow.log_param("1st_activation_funct", first_activation_funct) mlflow.log_param("1st_activation_funct", first_activation_funct)
mlflow.log_param("2nd_activation_funct", second_activation_funct) mlflow.log_param("2nd_activation_funct", second_activation_funct)
#mlflow.keras.log_model(model, 'my_model')
mlflow.keras.save_model(model, "my_model_mlflow")
mlflow.log_metric("accuracy", accuracy_score(y_true, y_pred)) mlflow.log_metric("accuracy", accuracy_score(y_true, y_pred))
tracking_url_type_store = urlparse(mlflow.get_tracking_uri()).scheme
if tracking_url_type_store != "file":
mlflow.sklearn.log_model(model, "my_model_mlflow", registered_model_name="s444517", signature=signature, input_example=input_example)
else:
mlflow.sklearn.log_model(model, "my_model_mlflow", signature=signature, input_example=input_example)
mlflow.keras.save_model(model, "my_model_mlflow", signature=signature, input_example=input_example)