Beispiel #1
0
print("Making predictions for the following 5 houses:")
print(X.head())
print("The predictions are")
print(melbourne_data.predict(X.head()))

#######################################################################
#Model Validation = Mean Absoulte Error(MAE): Error = Actual-Predicted
#On average, our predictions are off by about X.

import pandas as pd
#Load data
melbourne_file_path = ''
melbourne_data = pd.read_csv(melbourne_file_path)
#Filter rows with missing price values
filtered_melbourne_data = melbourne_data.dropna(axis=0)
#Choose target and features
y = filtered_melbourne_data.Price
melbourne_features = ['Rooms','Bathroom','Landsize','BuildingArea','YearBuilt','Latitude','Longitude']
X = filtered_melbourne_data[melbourne_features]

from sklearn.tree import DecisionTreeRegressor
#Define model
melbourne_model = DecisionTreeRegressor()
#Fit model
melbourne_model.fit(X,y)

from sklearn.metrics import mean_absolute_error
predicted_home_prices = melbourne_model.predict(X)
mean_absolute_error(y, predicted_home_prices)