This commit is contained in:
Szymon Bartanowicz 2024-05-18 19:42:40 +02:00
parent 57def16f1a
commit 248ef29471
53 changed files with 156 additions and 20 deletions

View File

@ -1,7 +1,7 @@
name: MLflow_s464937
conda_env: conda.yaml
entry_points:
optimal_parameters:
main:
parameters:
epochs: { type: int, default: 20 }
command: 'python mlflow_model.py {epochs}'

View File

@ -7,6 +7,8 @@ from sklearn.pipeline import Pipeline
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import tensorflow as tf
from sklearn.metrics import accuracy_score, precision_recall_fscore_support, mean_squared_error
from math import sqrt
import mlflow
@ -14,41 +16,63 @@ mlflow.set_tracking_uri("http://localhost:5000")
def main():
data = pd.read_csv('./data/train.csv')
data = pd.read_csv('../openpowerlifting.csv')
data = data[['Sex', 'Age', 'BodyweightKg', 'TotalKg']].dropna()
data['Age'] = pd.to_numeric(data['Age'], errors='coerce')
data['BodyweightKg'] = pd.to_numeric(data['BodyweightKg'], errors='coerce')
data['TotalKg'] = pd.to_numeric(data['TotalKg'], errors='coerce')
features = data[['Sex', 'Age', 'BodyweightKg']]
target = data['TotalKg']
X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.2, random_state=42)
preprocessor = ColumnTransformer(
transformers=[
('num', StandardScaler(), ['Age', 'BodyweightKg']),
('cat', OneHotEncoder(), ['Sex'])
],
)
with mlflow.start_run() as run:
preprocessor = ColumnTransformer(
transformers=[
('num', StandardScaler(), ['Age', 'BodyweightKg']),
('cat', OneHotEncoder(), ['Sex'])
],
)
pipeline = Pipeline(steps=[
('preprocessor', preprocessor),
('model', Sequential([
model = Sequential([
Dense(64, activation='relu', input_dim=5),
Dense(64, activation='relu'),
Dense(1)
]))
])
])
pipeline['model'].compile(optimizer='adam', loss='mse', metrics=['mae'])
model.compile(optimizer='adam', loss='mse', metrics=['mae'])
pipeline = Pipeline(steps=[
('preprocessor', preprocessor),
('model', model)
])
X_train_excluded = X_train.iloc[1:]
y_train_excluded = y_train.iloc[1:]
X_train_excluded = X_train.iloc[1:]
y_train_excluded = y_train.iloc[1:]
pipeline.fit(X_train_excluded, y_train_excluded, model__epochs=int(sys.argv[1]), model__validation_split=0.1)
pipeline['model'].save('powerlifting_model.h5')
loaded_model = tf.keras.models.load_model('powerlifting_model.h5')
pipeline.fit(X_train_excluded, y_train_excluded, model__epochs=int(sys.argv[1]), model__validation_split=0.1)
test_data = pd.read_csv('openpowerlifting.csv')
test_data = test_data[['Sex', 'Age', 'BodyweightKg', 'TotalKg']].dropna()
test_data['Age'] = pd.to_numeric(test_data['Age'], errors='coerce')
test_data['BodyweightKg'] = pd.to_numeric(test_data['BodyweightKg'], errors='coerce')
test_data['TotalKg'] = pd.to_numeric(test_data['TotalKg'], errors='coerce')
test_features = test_data[['Sex', 'Age', 'BodyweightKg']]
test_target = test_data['TotalKg']
pipeline['model'].save('powerlifting_model.h5')
X_test_transformed = preprocessor.transform(test_features)
predictions = loaded_model.predict(X_test_transformed)
predictions_df = pd.DataFrame(predictions, columns=['predicted_TotalKg'])
predictions_df['actual_TotalKg'] = test_target.reset_index(drop=True)
predictions_df.to_csv('powerlifting_test_predictions.csv', index=False)
data = pd.read_csv('powerlifting_test_predictions.csv')
y_pred = data['predicted_TotalKg']
y_test = data['actual_TotalKg']
rmse = sqrt(mean_squared_error(y_test, y_pred))
mlflow.log_param("epochs", int(sys.argv[1]))
mlflow.log_metric("rmse", rmse)
if __name__ == '__main__':

View File

@ -0,0 +1,6 @@
artifact_location: mlflow-artifacts:/0
creation_time: 1716052613528
experiment_id: '0'
last_update_time: 1716052613528
lifecycle_stage: active
name: Default

View File

@ -0,0 +1,15 @@
artifact_uri: mlflow-artifacts:/0/852a00be19a04756b19b2a0fdb0c6a83/artifacts
end_time: null
entry_point_name: ''
experiment_id: '0'
lifecycle_stage: active
run_id: 852a00be19a04756b19b2a0fdb0c6a83
run_name: skillful-worm-708
run_uuid: 852a00be19a04756b19b2a0fdb0c6a83
source_name: ''
source_type: 4
source_version: ''
start_time: 1716053034879
status: 1
tags: []
user_id: szymonbartanowicz

View File

@ -0,0 +1 @@
12

View File

@ -0,0 +1 @@
20

View File

@ -0,0 +1 @@
https://git.wmi.amu.edu.pl/s464937/ium_464937.git

View File

@ -0,0 +1 @@
conda

View File

@ -0,0 +1 @@
skillful-worm-708

View File

@ -0,0 +1 @@
57def16f1aff244cfe1e2bc1042a97b64459753e

View File

@ -0,0 +1 @@
https://git.wmi.amu.edu.pl/s464937/ium_464937.git

View File

@ -0,0 +1 @@
file:///Users/szymonbartanowicz/studia/mag_1/inzynieria_uczenia_maszynowego/ium_464937#mlflow

View File

@ -0,0 +1 @@
PROJECT

View File

@ -0,0 +1 @@
szymonbartanowicz

View File

@ -0,0 +1,15 @@
artifact_uri: mlflow-artifacts:/0/a7bad8d56b5a476193134123f3175c00/artifacts
end_time: 1716053941729
entry_point_name: ''
experiment_id: '0'
lifecycle_stage: active
run_id: a7bad8d56b5a476193134123f3175c00
run_name: brawny-stag-513
run_uuid: a7bad8d56b5a476193134123f3175c00
source_name: ''
source_type: 4
source_version: ''
start_time: 1716053939145
status: 4
tags: []
user_id: szymonbartanowicz

View File

@ -0,0 +1 @@
12

View File

@ -0,0 +1 @@
20

View File

@ -0,0 +1 @@
https://git.wmi.amu.edu.pl/s464937/ium_464937.git

View File

@ -0,0 +1 @@
local

View File

@ -0,0 +1 @@
conda

View File

@ -0,0 +1 @@
brawny-stag-513

View File

@ -0,0 +1 @@
57def16f1aff244cfe1e2bc1042a97b64459753e

View File

@ -0,0 +1 @@
https://git.wmi.amu.edu.pl/s464937/ium_464937.git

View File

@ -0,0 +1 @@
file:///Users/szymonbartanowicz/studia/mag_1/inzynieria_uczenia_maszynowego/ium_464937#mlflow

View File

@ -0,0 +1 @@
PROJECT

View File

@ -0,0 +1 @@
szymonbartanowicz

View File

@ -0,0 +1,15 @@
artifact_uri: mlflow-artifacts:/0/b7c7e490ed0f4a6d98293d275b5f67a9/artifacts
end_time: 1716053969998
entry_point_name: ''
experiment_id: '0'
lifecycle_stage: active
run_id: b7c7e490ed0f4a6d98293d275b5f67a9
run_name: zealous-crow-502
run_uuid: b7c7e490ed0f4a6d98293d275b5f67a9
source_name: ''
source_type: 4
source_version: ''
start_time: 1716053967858
status: 4
tags: []
user_id: szymonbartanowicz

View File

@ -0,0 +1 @@
12

View File

@ -0,0 +1 @@
https://git.wmi.amu.edu.pl/s464937/ium_464937.git

View File

@ -0,0 +1 @@
local

View File

@ -0,0 +1 @@
conda

View File

@ -0,0 +1 @@
zealous-crow-502

View File

@ -0,0 +1 @@
57def16f1aff244cfe1e2bc1042a97b64459753e

View File

@ -0,0 +1 @@
https://git.wmi.amu.edu.pl/s464937/ium_464937.git

View File

@ -0,0 +1 @@
file:///Users/szymonbartanowicz/studia/mag_1/inzynieria_uczenia_maszynowego/ium_464937#mlflow

View File

@ -0,0 +1 @@
PROJECT

View File

@ -0,0 +1 @@
szymonbartanowicz

View File

@ -0,0 +1,15 @@
artifact_uri: mlflow-artifacts:/0/dd9e039328564f8bb20449bd7bea8ab1/artifacts
end_time: 1716053927316
entry_point_name: ''
experiment_id: '0'
lifecycle_stage: active
run_id: dd9e039328564f8bb20449bd7bea8ab1
run_name: efficient-cod-832
run_uuid: dd9e039328564f8bb20449bd7bea8ab1
source_name: ''
source_type: 4
source_version: ''
start_time: 1716053923906
status: 4
tags: []
user_id: szymonbartanowicz

View File

@ -0,0 +1 @@
12

View File

@ -0,0 +1 @@
20

View File

@ -0,0 +1 @@
https://git.wmi.amu.edu.pl/s464937/ium_464937.git

View File

@ -0,0 +1 @@
local

View File

@ -0,0 +1 @@
conda

View File

@ -0,0 +1 @@
efficient-cod-832

View File

@ -0,0 +1 @@
57def16f1aff244cfe1e2bc1042a97b64459753e

View File

@ -0,0 +1 @@
https://git.wmi.amu.edu.pl/s464937/ium_464937.git

View File

@ -0,0 +1 @@
file:///Users/szymonbartanowicz/studia/mag_1/inzynieria_uczenia_maszynowego/ium_464937#mlflow

View File

@ -0,0 +1 @@
PROJECT

View File

@ -0,0 +1 @@
szymonbartanowicz