ium_464962/predict.py

28 lines
863 B
Python
Raw Normal View History

2024-04-28 20:29:40 +02:00
import pandas as pd
import numpy as np
from tensorflow.keras import Sequential
import tensorflow as tf
from sklearn.preprocessing import MinMaxScaler
2024-05-13 21:05:29 +02:00
test_data = pd.read_csv('./data/car_prices_test.csv')
2024-04-28 20:29:40 +02:00
test_data.dropna(inplace=True)
y_test = test_data['sellingprice'].astype(np.float32)
X_test = test_data[['year', 'condition', 'transmission']]
scaler_y = MinMaxScaler()
scaler_y.fit(y_test.values.reshape(-1, 1))
scaler_X = MinMaxScaler()
X_test['condition'] = scaler_X.fit_transform(X_test[['condition']])
X_test = pd.get_dummies(X_test, columns=['transmission'])
2024-05-13 21:03:34 +02:00
model = tf.keras.models.load_model('./car_prices_predict_model.h5')
2024-04-28 20:29:40 +02:00
y_pred_scaled = model.predict(X_test)
y_pred = scaler_y.inverse_transform(y_pred_scaled)
y_pred_df = pd.DataFrame(y_pred, columns=['PredictedSellingPrice'])
y_pred_df.to_csv('predicted_selling_prices.csv', index=False)