From 074d4cd5daff3344f0b01343049648f1bed150af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudziak?= Date: Wed, 10 May 2023 13:20:14 +0200 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- predict.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 predict.py diff --git a/predict.py b/predict.py new file mode 100644 index 0000000..cf8b9d0 --- /dev/null +++ b/predict.py @@ -0,0 +1,31 @@ +import tensorflow as tf +import pandas as pd +import numpy as np +import sklearn +import sklearn.model_selection +from tensorflow.keras.models import load_model +from sklearn.metrics import accuracy_score, precision_score, f1_score + +feature_cols = ['year', 'mileage', 'vol_engine'] + +model = load_model('model.h5') +test_data = pd.read_csv('test.csv') + +predictions = model.predict(test_data[feature_cols]) +predicted_prices = [p[0] for p in predictions] + + +results = pd.DataFrame({'id': test_data['id'], 'year': test_data['year'], 'mileage': test_data['mileage'], 'vol_engine': test_data['vol_engine'], 'predicted_price': predicted_prices}) +results.to_csv('predictions.csv', index=False) + +y_true = test_data['price'] +y_pred = y_pred = [round(p[0]) for p in predictions] + +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: + f.write(f"Accuracy: {accuracy:.4f}\n") + f.write(f"Micro-average Precision: {precision:.4f}\n") + f.write(f"Micro-average F1-score: {f1:.4f}\n") \ No newline at end of file