To get a price prediction from your trained model, you do not include the Selling_Price (target column) in the input data. Instead, you provide a new row of data without the price, and the model will predict it for you.
✅ Step-by-Step: Predict Price from New Data
Here’s how to use your trained model (best_price_model.joblib) to predict prices:
1. Load the Trained Model
You saved the best model at the end of your notebook using joblib. First, load it back:
import joblib
# Load the saved model
model = joblib.load("best_price_model.joblib")
2. Prepare New Input Data
You must format the new data exactly like the training data — same columns, types, and preprocessing (e.g., no target column, correct categorical encoding).
Example: Predicting Price for a New Car
Assume your dataset includes these features (from your Geely dataset):
| Feature | Description |
|---|
| Car_Name | Name of the car |
| Year | Year of manufacture |
| Kms_Driven | Kilometers driven |
| Fuel_Type | Fuel type (Petrol/Diesel/CNG) |
Let’s say you want to predict the price of a Geely Coolray 2021, driven 25,000 km, with Petrol engine.
# Create a DataFrame with new data (no target column)
new_data = pd.DataFrame({
"Car_Name": ["Geely Coolray"],
"Year": [2021],
"Kms_Driven": [25000],
"Fuel_Type": ["Petrol"]
})
3. Make Prediction
Use the model’s .predict() method to get the predicted price:
predicted_price = model.predict(new_data)
print(f"Predicted Selling Price: ₹{predicted_price[0]:,.2f}")
💡 If you're using a regression model (like in your Geely example), .predict() returns the numeric price directly.
🔁 Why This Works
Your model was trained using a pipeline that includes:
- Feature preprocessing (scaling numeric columns, one-hot encoding categorical ones)
- The best-trained regression algorithm (e.g., XGBoost, Random Forest)
When you call .predict(), the pipeline automatically applies all preprocessing steps to the new data and then feeds it into the trained model.
🧠 Important Notes
| Concept | Explanation |
|---|
| Don’t include the target column | Your model was trained to predict Selling_Price, so it must not be present in the input data. |
| Same feature names and order | Ensure the new data has the same column names and order as the training data. |
| Categorical encoding | The pipeline handles this automatically (e.g., one-hot encoding), even if categories were unseen during training (thanks to handle_unknown="ignore"). |
| Numeric scaling | The pipeline scales numeric features (e.g., Year, Kms_Driven) using StandardScaler. You don’t need to do this manually. |
📦 Optional: Save Predictions to CSV
If you have multiple rows to predict:
# Predict for multiple new cars
new_cars = pd.DataFrame([
{"Car_Name": "Geely Coolray", "Year": 2021, "Kms_Driven": 25000, "Fuel_Type": "Petrol"},
{"Car_Name": "Geely Emgrand", "Year": 2020, "Kms_Driven": 45000, "Fuel_Type": "Diesel"},
])
new_cars["Predicted_Price"] = model.predict(new_cars)
# Save results
new_cars.to_csv("predicted_prices.csv", index=False)
🧪 Example Output
Predicted Selling Price: ₹782,340.00
This means the model estimates the car’s selling price at ₹782,340 based on its features.
✅ Summary
- ✅ Input: A new row of data without the
Selling_Price column.
- ✅ Process: Pipeline automatically preprocesses the data and runs the model.
- ✅ Output: A numeric price prediction (e.g.,
782340.0).
- ✅ Best Practice: Always validate predictions on real-world data if possible.
Let me know if you want to build a simple Streamlit app or Flask API to serve this model for real-time predictions! 🚀