Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,54 +75,29 @@ def load_model_and_encodings():
|
|
| 75 |
raise e
|
| 76 |
|
| 77 |
def predict_price(model, brand, model_name, year):
|
| 78 |
-
# Create a dictionary with default values
|
| 79 |
input_data = {
|
| 80 |
'year': year,
|
| 81 |
-
'make': brand,
|
| 82 |
-
'model': model_name,
|
| 83 |
-
'trim': 'Base', # Default trim
|
| 84 |
-
'condition': 'Used', # Default condition
|
| 85 |
-
'fuel': 'Gasoline', # Default fuel type
|
| 86 |
'odometer': year * 12000, # Estimate based on year and average annual mileage
|
| 87 |
-
'
|
| 88 |
-
'
|
| 89 |
-
'
|
| 90 |
-
'
|
| 91 |
-
'
|
| 92 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
-
# Calculate age and other required fields
|
| 96 |
-
current_year = datetime.now().year
|
| 97 |
-
input_data['age'] = current_year - year
|
| 98 |
-
input_data['age_squared'] = input_data['age'] ** 2
|
| 99 |
-
input_data['mileage_per_year'] = 12000 # Assuming average annual mileage
|
| 100 |
-
|
| 101 |
# Prepare the input for the model
|
| 102 |
input_df = pd.DataFrame([input_data])
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
|
| 106 |
-
'make': 'Make',
|
| 107 |
-
'model': 'Model',
|
| 108 |
-
'year': 'Year',
|
| 109 |
-
'trim': 'Trim',
|
| 110 |
-
'condition': 'Condition',
|
| 111 |
-
'fuel': 'Fuel',
|
| 112 |
-
'odometer': 'Odometer',
|
| 113 |
-
'title_status': 'Title_status',
|
| 114 |
-
'transmission': 'Transmission',
|
| 115 |
-
'drive': 'Drive',
|
| 116 |
-
'size': 'Size',
|
| 117 |
-
'type': 'Type',
|
| 118 |
-
'paint_color': 'Paint_color',
|
| 119 |
-
'age': 'Age',
|
| 120 |
-
'age_squared': 'Age_squared',
|
| 121 |
-
'mileage_per_year': 'Mileage_per_year'
|
| 122 |
-
})
|
| 123 |
-
|
| 124 |
-
# Make sure to only include columns that the model expects
|
| 125 |
-
model_columns = model.feature_names_in_
|
| 126 |
input_df = input_df[model_columns]
|
| 127 |
|
| 128 |
# Predict the price
|
|
|
|
| 75 |
raise e
|
| 76 |
|
| 77 |
def predict_price(model, brand, model_name, year):
|
| 78 |
+
# Create a dictionary with default values for the specified categories
|
| 79 |
input_data = {
|
| 80 |
'year': year,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
'odometer': year * 12000, # Estimate based on year and average annual mileage
|
| 82 |
+
'age': datetime.now().year - year,
|
| 83 |
+
'age_squared': (datetime.now().year - year) ** 2,
|
| 84 |
+
'mileage_per_year': 12000,
|
| 85 |
+
'model': model_name,
|
| 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 |
+
# Make sure to only include the specified columns
|
| 100 |
+
model_columns = [col for col in model.feature_names_in_ if col in input_data.keys()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
input_df = input_df[model_columns]
|
| 102 |
|
| 103 |
# Predict the price
|