mlflow task added
All checks were successful
s434742-training/pipeline/head This commit looks good
s434742-evaluation/pipeline/head This commit looks good

This commit is contained in:
patrycjalazna 2021-05-15 14:18:38 +02:00
parent 9b2764a4c0
commit 60ec48f83c
3 changed files with 84 additions and 1 deletions

11
MLproject Normal file
View File

@ -0,0 +1,11 @@
name: 434742-mlflow
docker_env:
image: patlaz/ium:1.0
entry_points:
main:
parameters:
epochs: {type: int, default: 10}
batch_size: {type: int, default: 16}
command: "python3 avocado-mlflow.py {epochs} {batch_size}"

71
avocado-mlflow.py Normal file
View File

@ -0,0 +1,71 @@
import sys
from keras.backend import batch_dot, mean
import pandas as pd
import numpy as np
from six import int2byte
from sklearn import preprocessing
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Input, Dense, Activation,Dropout
from tensorflow.keras.models import Model
from tensorflow.keras.callbacks import EarlyStopping
from keras.models import Sequential
import mlflow
def my_main(epochs, batch_size):
# odczytanie danych z plików
avocado_train = pd.read_csv('avocado_train.csv')
avocado_test = pd.read_csv('avocado_test.csv')
avocado_validate = pd.read_csv('avocado_validate.csv')
# podzial na X i y
X_train = avocado_train[['average_price', 'total_volume', '4046', '4225', '4770', 'total_bags', 'small_bags', 'large_bags', 'xlarge_bags']]
y_train = avocado_train[['type']]
X_test = avocado_test[['average_price', 'total_volume', '4046', '4225', '4770', 'total_bags', 'small_bags', 'large_bags', 'xlarge_bags']]
y_test = avocado_test[['type']]
print(X_train.shape[1])
# keras model
model = Sequential()
model.add(Dense(9, input_dim = X_train.shape[1], kernel_initializer='normal', activation='relu'))
model.add(Dense(1,kernel_initializer='normal', activation='sigmoid'))
early_stop = EarlyStopping(monitor="val_loss", mode="min", verbose=1, patience=10)
# kompilacja
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# trenowanie modelu
model.fit(X_train, y_train, epochs=epochs, batch_size=batch_size, validation_data=(X_test, y_test))
# predykcja
prediction = model.predict(X_test)
# ewaluacja
rmse = mean_squared_error(y_test, prediction)
# zapisanie modelu
model.save('avocado_model.h5')
return rmse, model
epochs = int(sys.argv[1]) if len(sys.argv) > 1 else 15
batch_size = int(sys.argv[2]) if len(sys.argv) > 2 else 16
with mlflow.start_run():
rmse, model = my_main(epochs, batch_size)
mlflow.log_param("epochs", epochs)
mlflow.log_param("batch_size", batch_size)
mlflow.log_metric("rmse", rmse)
mlflow.keras.log_model(model, 'avocado_model.h5')

View File

@ -6,4 +6,5 @@ numpy==1.19.5
kaggle==1.5.12
keras==2.4.3
scikit_learn==0.24.2
pymongo
pymongo
mlflow