-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoAvm.py
More file actions
41 lines (32 loc) · 1.45 KB
/
Copy pathautoAvm.py
File metadata and controls
41 lines (32 loc) · 1.45 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
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error, r2_score
import joblib
# Load your dataset containing property features and market values
dataset = pd.read_csv('your_dataset.csv')
# Prepare the data by selecting the feature columns and the target column
X = dataset[['square_footage', 'age', 'num_rooms', 'num_bathrooms', 'location_score']]
y = dataset['market_value']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Standardize the data for better model performance
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
# Train the RandomForestRegressor model
model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(X_train_scaled, y_train)
# Make predictions and evaluate the model performance
y_pred = model.predict(X_test_scaled)
mse = mean_squared_error(y_test, y_pred)
rmse = np.sqrt(mse)
r2 = r2_score(y_test, y_pred)
print(f'Mean Squared Error: {mse}')
print(f'Root Mean Squared Error: {rmse}')
print(f'R2 Score: {r2}')
# Save the model and scaler for later use
joblib.dump(model, 'property_valuation_model.pkl')
joblib.dump(scaler, 'property_valuation_scaler.pkl')