-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
122 lines (104 loc) · 3.64 KB
/
Copy pathdemo.py
File metadata and controls
122 lines (104 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
"""
Machine Learning Price Predictor Demo
=====================================
This script demonstrates how to use the trained price prediction model
to predict house prices based on various features.
"""
import sys
import os
sys.path.append('src')
from simple_model import predict_price_from_saved_model
def main():
print("🏠 Machine Learning Price Predictor Demo")
print("=" * 50)
model_path = 'models/simple_price_model.pkl'
# Check if model exists
if not os.path.exists(model_path):
print("❌ Model not found! Please run 'python src/simple_model.py' first to train the model.")
return
print("✅ Model loaded successfully!")
print("\nThis model predicts house prices based on:")
print("• Size (square feet)")
print("• Number of bedrooms")
print("• Number of bathrooms")
print("• Location score (1-10)")
print("• Age (years)")
print("• Garage (0=No, 1=Yes)")
# Demo predictions
print("\n🔮 Sample Predictions:")
print("-" * 30)
sample_houses = [
{
'name': 'Starter Home',
'size': 1200,
'bedrooms': 2,
'bathrooms': 1,
'location_score': 6.5,
'age': 15,
'garage': 0
},
{
'name': 'Family Home',
'size': 2000,
'bedrooms': 3,
'bathrooms': 2,
'location_score': 8.0,
'age': 7,
'garage': 1
},
{
'name': 'Luxury Home',
'size': 3000,
'bedrooms': 5,
'bathrooms': 4,
'location_score': 9.5,
'age': 2,
'garage': 1
}
]
for house in sample_houses:
try:
predicted_price = predict_price_from_saved_model(
model_path,
house['size'],
house['bedrooms'],
house['bathrooms'],
house['location_score'],
house['age'],
house['garage']
)
print(f"\n🏡 {house['name']}:")
print(f" Size: {house['size']:,} sqft")
print(f" Bedrooms: {house['bedrooms']}")
print(f" Bathrooms: {house['bathrooms']}")
print(f" Location Score: {house['location_score']}")
print(f" Age: {house['age']} years")
print(f" Garage: {'Yes' if house['garage'] else 'No'}")
print(f" 💰 Predicted Price: ${predicted_price:,.2f}")
except Exception as e:
print(f"❌ Error predicting price for {house['name']}: {e}")
# Interactive prediction
print("\n" + "=" * 50)
print("🎯 Try Your Own Prediction!")
print("=" * 50)
try:
print("\nEnter house details:")
size = float(input("Size (square feet): "))
bedrooms = int(input("Bedrooms: "))
bathrooms = int(input("Bathrooms: "))
location_score = float(input("Location score (1-10): "))
age = int(input("Age (years): "))
garage = int(input("Garage (0=No, 1=Yes): "))
predicted_price = predict_price_from_saved_model(
model_path, size, bedrooms, bathrooms, location_score, age, garage
)
print(f"\n🎉 Predicted Price: ${predicted_price:,.2f}")
except KeyboardInterrupt:
print("\n\n👋 Thanks for using the Price Predictor!")
except ValueError:
print("❌ Please enter valid numbers for all fields.")
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
main()