Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -76,29 +76,29 @@ def load_model_and_encodings():
|
|
76 |
def predict_price(model, brand, model_name, year):
|
77 |
# Create a dictionary with default values for the specified categories
|
78 |
input_data = {
|
79 |
-
'
|
80 |
-
'
|
81 |
-
'
|
82 |
-
'
|
83 |
-
'
|
84 |
-
'Make': brand, #
|
85 |
-
'
|
86 |
-
'
|
87 |
-
'
|
88 |
-
'
|
89 |
-
'
|
90 |
-
'
|
91 |
-
'
|
92 |
-
'
|
93 |
-
'
|
94 |
}
|
95 |
|
96 |
# Prepare the input for the model
|
97 |
input_df = pd.DataFrame([input_data])
|
98 |
|
99 |
-
#
|
100 |
-
|
101 |
-
input_df = input_df[
|
102 |
|
103 |
# Predict the price
|
104 |
predicted_price = model.predict(input_df)
|
|
|
76 |
def predict_price(model, brand, model_name, year):
|
77 |
# Create a dictionary with default values for the specified categories
|
78 |
input_data = {
|
79 |
+
'year': year,
|
80 |
+
'odometer': year * 12000, # Estimate based on year and average annual mileage
|
81 |
+
'age': datetime.now().year - year,
|
82 |
+
'age_squared': (datetime.now().year - year) ** 2,
|
83 |
+
'mileage_per_year': 12000,
|
84 |
+
'Make': brand, # Note the capital 'M' in Make
|
85 |
+
'model': model_name, # lowercase 'model'
|
86 |
+
'condition': 'Used',
|
87 |
+
'fuel': 'Gasoline',
|
88 |
+
'title_status': 'Clean',
|
89 |
+
'transmission': 'Automatic',
|
90 |
+
'drive': 'Fwd',
|
91 |
+
'size': 'Mid-Size',
|
92 |
+
'type': 'Sedan',
|
93 |
+
'paint_color': 'White'
|
94 |
}
|
95 |
|
96 |
# Prepare the input for the model
|
97 |
input_df = pd.DataFrame([input_data])
|
98 |
|
99 |
+
# Ensure all expected columns are present and in the correct order
|
100 |
+
expected_columns = ['year', 'odometer', 'age', 'age_squared', 'mileage_per_year', 'Make', 'model', 'condition', 'fuel', 'title_status', 'transmission', 'drive', 'size', 'type', 'paint_color']
|
101 |
+
input_df = input_df[expected_columns]
|
102 |
|
103 |
# Predict the price
|
104 |
predicted_price = model.predict(input_df)
|