1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
import joblib
import pandas as pd
# Load the model
mileage_model = joblib.load('mileage_predictor.pkl')
price_model = joblib.load('price_predictor.pkl')
year_model = joblib.load('year_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]
year = year_model.predict(prepared_data)[0]
return mileage, price, int(year)
def collect_input():
print("Enter the car details for prediction:")
year = int(input("Year of Manufacture (e.g., 2022): "))
kilometers_driven = int(input("Kilometers Driven (e.g., 30000): "))
fuel_type = input("Fuel Type (Petrol/Diesel/CNG/Electric): ")
transmission = input("Transmission (Manual/Automatic): ")
owner_type = input("Owner Type (First/Second/Third/Fourth & Above): ")
location = input("Location (e.g., Mumbai): ")
engine_cc = int(input("Engine Capacity in CC (e.g., 1200): "))
power = float(input("Power in BHP (e.g., 85): "))
seats = int(input("Number of Seats (e.g., 5): "))
return {
'Year': year,
'Kilometers_Driven': kilometers_driven,
'Fuel_Type': fuel_type,
'Transmission': transmission,
'Owner_Type': owner_type,
'Location': location,
'Engine CC': engine_cc,
'Power': power,
'Seats': seats
}
# Collect input data from the user
data = collect_input()
# Make prediction
predicted_mileage, predicted_price, predicted_year = predict(data)
print("\nPrediction Results:")
print(f"Predicted Mileage (Km/L): {predicted_mileage:.2f}")
print(f"Predicted Price: ₹{predicted_price:,.2f} Lakhs")
print(f"Predicted Year: {predicted_year}")
|