Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions python/code/Chapter 4 - Regression and Prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ def partialResidualPlot(model, df, outcome, feature, ax):
'ypartial': feature_prediction - model.params[0],
})
results = results.sort_values(by=['feature'])
smoothed = sm.nonparametric.lowess(results.ypartial, results.feature, frac=1/3)
smoothed = sm.nonparametric.lowess(results.ypartial + results.residual,
results.feature, frac=1/3)

ax.scatter(results.feature, results.ypartial + results.residual)
ax.plot(smoothed[:, 0], smoothed[:, 1], color='gray')
Expand Down Expand Up @@ -577,4 +578,4 @@ def partialResidualPlot(model, df, outcome, feature, ax):
# Bathrooms: 42403.059999677665
# PropertyType_Townhouse: 84378.9333363999
# SqFtFinBasement: 7.032178917565108
# PropertyType_Single Family: 22854.87954019308
# PropertyType_Single Family: 22854.87954019308
Loading