Views
No views yet
iterations=2500, depth=10, learning_rate=0.045, loss_function="MAE", eval_metric="MAE", random_seed=42, verbose=200.area_rate. Also created "area buckets" for better performance.| Metric | Value |
|---|---|
| Testing MAE | 3.86k |
| Testing R-squared | 0.9351 |
1def predict_user_rent(model, raw_df):
2 print("\n\n========== RENT PREDICTION ASSISTANT ==========\n")
3 print("Choose values for each feature below. For categorical vars, pick a number.\n")
4
5 sample = {}
6
7 # Menu
8 def choose_cat(col_name):
9 unique_vals = sorted(raw_df[col_name].unique())
10 print(f"\n--- {col_name} ---")
11 for idx, val in enumerate(unique_vals):
12 print(f"{idx + 1}. {val}")
13 sel = int(input("Enter your choice number: ")) - 1
14 return unique_vals[sel]
15
16 # Categorical
17 sample["house_type"] = choose_cat("house_type")
18 sample["locality"] = choose_cat("locality")
19 sample["city"] = choose_cat("city")
20 sample["furnishing"] = choose_cat("furnishing")
21
22 # Numeric values
23 def choose_num(col_name):
24 return float(input(f"\nEnter value for {col_name}: "))
25
26 sample["area"] = choose_num("area")
27 sample["beds"] = choose_num("beds")
28 sample["bathrooms"] = choose_num("bathrooms")
29 sample["balconies"] = choose_num("balconies")
30
31 # area bucket
32 area_val = sample["area"]
33 area_bins = [0, 300, 600, 900, 1200, 2000, 5000, 100000]
34 area_bucket = np.digitize([area_val], area_bins)[0] - 1
35 sample["area_bucket"] = area_bucket
36
37 # placeholder for rent_psf bucket (we don't know rent yet)
38 # so we use area only as a proxy for typical price density
39 sample["rent_psf_bucket"] = min(int(area_bucket), 19)
40
41 df_input = pd.DataFrame([sample])
42
43 # Must match training encodings
44 for col in ["house_type", "locality", "city", "furnishing"]:
45 df_input[col] = df_input[col].astype(raw_df[col].dtype)
46
47 # Prediction
48 pred_log = model.predict(df_input)[0]
49 pred_rent = np.expm1(pred_log)
50
51 print("\n===================================")
52 print(f"Estimated Rent: ₹ {pred_rent:,.2f}")
53 print("===================================\n")
54
55 return pred_rent
56
57# Uncomment to use interactively:
58# predict_user_rent(model, df)