-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_model.py
More file actions
29 lines (22 loc) · 770 Bytes
/
train_model.py
File metadata and controls
29 lines (22 loc) · 770 Bytes
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
import pandas as pd
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_absolute_error
path_in = 'dados/melb_data.csv'
data = pd.read_csv(path_in)
data_process = data.dropna(axis=0)
y = data_process.Price
melbourne_features = ['Rooms', 'Bathroom', 'Landsize', 'Lattitude', 'Longtitude']
X = data_process[melbourne_features]
X.describe()
X.head()
melbourne_model = DecisionTreeRegressor(random_state=1)
melbourne_model.fit(X, y)
print("Making predictions for the following 5 houses:")
print(X.head())
print("The predictions are")
print(melbourne_model.predict(X.head()))
print("Actual values")
print(y.head().to_list())
# Validando modelo
predicted_home_prices = melbourne_model.predict(X)
mean_absolute_error(y, predicted_home_prices)