-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit. I've already played around with the first two exercises.
- Loading branch information
0 parents
commit 5b0c885
Showing
13,871 changed files
with
231,488 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
01_training_a_linear_regression_model/extra_credit_train_gradient_boosting_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pandas as pd | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.ensemble import GradientBoostingRegressor | ||
from sklearn.metrics import mean_absolute_error | ||
from sklearn.externals import joblib | ||
|
||
# Load our data set | ||
df = pd.read_csv("house_data.csv") | ||
|
||
# Create the X and y arrays | ||
X = df[["sq_feet", "num_bedrooms", "num_bathrooms"]] | ||
y = df["sale_price"] | ||
|
||
# Split the data set in a training set (75%) and a test set (25%) | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25) | ||
|
||
# Create the Linear Regression model | ||
model = GradientBoostingRegressor() | ||
|
||
# Train the model | ||
model.fit(X_train, y_train) | ||
|
||
# Save the trained model to a file so we can use it to make predictions later | ||
joblib.dump(model, 'house_value_model.pkl') | ||
|
||
# Report how well the model is performing | ||
print("Model training results:") | ||
|
||
# Report an error rate on the training set | ||
mse_train = mean_absolute_error(y_train, model.predict(X_train)) | ||
print(f" - Training Set Error: {mse_train}") | ||
|
||
# Report an error rate on the test set | ||
mse_test = mean_absolute_error(y_test, model.predict(X_test)) | ||
print(f" - Test Set Error: {mse_test}") | ||
|
Oops, something went wrong.