EdBoy2202 commited on
Commit
c68bcf4
·
verified ·
1 Parent(s): abf040d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
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
- '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, # Use the separated make
85
- 'Model': model_name, # Use the separated model
86
- 'Condition': 'Used', # Default condition
87
- 'Fuel': 'Gasoline', # Default fuel type
88
- 'Title_status': 'Clean', # Default title status
89
- 'Transmission': 'Automatic', # Default transmission
90
- 'Drive': 'Fwd', # Default drive
91
- 'Size': 'Mid-Size', # Default size
92
- 'Type': 'Sedan', # Default type
93
- 'Paint_color': 'White' # Default color
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
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)