|
import pandas as pd |
|
from sklearn.preprocessing import LabelEncoder |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.ensemble import GradientBoostingRegressor |
|
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score, median_absolute_error |
|
from joblib import dump |
|
|
|
|
|
df = pd.read_csv('cleaned_housesTRAIN.csv') |
|
|
|
|
|
le_area = LabelEncoder() |
|
df['Area'] = le_area.fit_transform(df['Area']) |
|
|
|
le_suburb = LabelEncoder() |
|
df['Suburb'] = le_suburb.fit_transform(df['Suburb']) |
|
|
|
|
|
dump(le_area, 'le_area.joblib') |
|
dump(le_suburb, 'le_suburb.joblib') |
|
|
|
|
|
df = df.sample(frac=1) |
|
|
|
|
|
X = df.drop('Rent', axis=1) |
|
y = df['Rent'] |
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42) |
|
|
|
|
|
gb = GradientBoostingRegressor(n_estimators=850, learning_rate=0.195, max_depth=7, random_state=42) |
|
|
|
|
|
gb.fit(X_train, y_train) |
|
|
|
|
|
y_pred = gb.predict(X_test) |
|
|
|
|
|
mae = mean_absolute_error(y_test, y_pred) |
|
mse = mean_squared_error(y_test, y_pred) |
|
r2 = r2_score(y_test, y_pred) |
|
medae = median_absolute_error(y_test, y_pred) |
|
|
|
print(f"MAE: {mae}, MSE: {mse}, R2: {r2}, MedAE: {medae}") |
|
|
|
|
|
dump(gb, 'bestmodelyet.joblib') |
|
|
|
|