Zaktualizuj 'predict.py'

This commit is contained in:
Michał Dudziak 2023-05-11 13:55:56 +02:00
parent cf6e265d7a
commit 0405205089

View File

@ -4,7 +4,18 @@ import numpy as np
import sklearn import sklearn
import sklearn.model_selection import sklearn.model_selection
from tensorflow.keras.models import load_model from tensorflow.keras.models import load_model
from sklearn.metrics import accuracy_score, precision_score, f1_score from sklearn.metrics import mean_absolute_error, mean_squared_error
import mlflow
# Wskazujemy ścieżkę do folderu, gdzie zostaną zapisane wyniki MLflow
mlflow.set_tracking_uri("file:/mlflow")
# Ustawiamy nazwę eksperymentu
mlflow.set_experiment("nazwa eksperymentu")
feature_cols = ['year', 'mileage', 'vol_engine']
feature_cols = ['year', 'mileage', 'vol_engine'] feature_cols = ['year', 'mileage', 'vol_engine']
@ -19,16 +30,13 @@ results = pd.DataFrame({'id': test_data['id'], 'year': test_data['year'], 'milea
results.to_csv('predictions.csv', index=False) results.to_csv('predictions.csv', index=False)
y_true = test_data['price'] y_true = test_data['price']
y_pred = y_pred = [round(p[0]) for p in predictions] y_pred = [round(p[0]) for p in predictions]
print(y_pred) mae = mean_absolute_error(y_true, y_pred)
print(y_true) mse = mean_squared_error(y_true, y_pred)
rmse = np.sqrt(mse)
accuracy = accuracy_score(y_true, y_pred)
precision = precision_score(y_true, y_pred, average='micro')
f1 = f1_score(y_true, y_pred, average='micro')
with open('metrics.txt', 'w') as f: with open('metrics.txt', 'w') as f:
f.write(f"Accuracy: {accuracy:.4f}\n") f.write(f"MAE: {mae:.4f}\n")
f.write(f"Micro-average Precision: {precision:.4f}\n") f.write(f"MSE: {mse:.4f}\n")
f.write(f"Micro-average F1-score: {f1:.4f}\n") f.write(f"RMSE: {rmse:.4f}\n")