diff options
Diffstat (limited to 'predict.py')
-rw-r--r-- | predict.py | 48 |
1 files changed, 33 insertions, 15 deletions
@@ -2,25 +2,43 @@ import joblib import pandas as pd # Load the model -model = joblib.load('model.pkl') +mileage_model = joblib.load('mileage_predictor.pkl') +price_model = joblib.load('price_predictor.pkl') + +# Prepare input data for prediction +def prepare_input(data_dict): + # Prepare a DataFrame from a dictionary of input data + input_df = pd.DataFrame([data_dict]) + input_df['Car_Age'] = 2024 - input_df['Year'] + input_df.drop(columns=['Year'], inplace=True) + + return input_df + +# Make prediction +def predict(input_data): + # Predict mileage and price for a given input. + prepared_data = prepare_input(input_data) + mileage = mileage_model.predict(prepared_data)[0] + price = price_model.predict(prepared_data)[0] + + return mileage, price # Sample data for prediction data = { - 'Kilometers_Driven': [50000], - 'Fuel_Type': ['Petrol'], - 'Transmission': ['Manual'], - 'Owner_Type': ['First'], - 'Engine CC': [1197], - 'Power': [82], - 'Seats': [5], - 'Car_Age': [6], - 'Location': ['Mumbai'] + 'Year': 2018, + 'Kilometers_Driven': 30000, + 'Fuel_Type': 'Petrol', + 'Transmission': 'Manual', + 'Owner_Type': 'First', + 'Location': 'Mumbai', + 'Engine CC': 1200, + 'Power': 85, + 'Seats': 5 } -# Convert to DataFrame -input_data = pd.DataFrame(data) +# Make prediction -# Predict -predicted_mileage = model.predict(input_data) +predicted_mileage, predicted_price = predict(data) -print(f"Predicted Mileage: {predicted_mileage[0]:.2f} Km/L") +print(f"Predicted Mileage (Km/L): {predicted_mileage:.2f}") +print(f"Predicted Price: ₹{predicted_price:,.2f} Lakhs") |