Partial dependence plots

In addition to the summary contribution of individual features to the model's prediction, partial dependence plots visualize the relationship between the target variable and a set of features. The nonlinear nature of gradient boosting trees causes this relationship to depends on the values of all other features. Hence, we will marginalize these features out. By doing so, we can interpret the partial dependence as the expected target response. 

We can visualize partial dependence only for individual features or feature pairs. The latter results in contour plots that show how combinations of feature values produce different predicted probabilities, as shown in the following code:

fig, axes = plot_partial_dependence(gbrt=gb_clf,
X=X_dummies_clean,
features=['month_9', 'return_1m', 'return_3m', ('return_1m', 'return_3m')],
feature_names=['month_9','return_1m', 'return_3m'],
percentiles=(0.01, 0.99),
n_jobs=-1,
n_cols=2,
grid_resolution=250)

After some additional formatting (see the companion notebook), we obtain the following plot:

The lower-right plot shows the dependence of the probability of a positive return over the next month given the range of values for lagged 1-month and 3-month returns after eliminating outliers at the [1%, 99%] percentiles. The month_9 variable is a dummy variable, hence the step-function-like plot. We can also visualize the dependency in 3D, as shown in the following code:

targets = ['return_1m', 'return_3m']
target_feature = [X_dummies_clean.columns.get_loc(t) for t in targets]
pdp, axes = partial_dependence(gb_clf,
target_feature,
X=X_dummies_clean,
grid_resolution=100)

XX, YY = np.meshgrid(axes[0], axes[1])
Z = pdp[0].reshape(list(map(np.size, axes))).T

fig = plt.figure(figsize=(14, 8))
ax = Axes3D(fig)
surf = ax.plot_surface(XX, YY, Z,
rstride=1,
cstride=1,
cmap=plt.cm.BuPu,
edgecolor='k')
ax.set_xlabel(' '.join(targets[0].split('_')).capitalize())
ax.set_ylabel(' '.join(targets[1].split('_')).capitalize())
ax.set_zlabel('Partial Dependence')
ax.view_init(elev=22, azim=30)

This produces the following 3D plot of the partial dependence of the 1-month return direction on lagged 1-month and 3-months returns:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
54.144.219.156