Prześlij pliki do ''

This commit is contained in:
Michał Dudziak 2023-05-10 13:20:14 +02:00
parent 13aff1e3c3
commit 074d4cd5da

31
predict.py Normal file
View File

@ -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")