13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

231

if __name__ == "__main__":

# Set up the X and Y dimensions

fig = plt.figure()

ax = Axes3D(fig)

X = np.arange(0, 20, 0.25)

Y = np.arange(-10, 10, 0.25)

X, Y = np.meshgrid(X, Y)

# Create the univarate normal coefficients

# of intercept and slope, as well as the

# conditional probability density

beta0 = -5.0

beta1 = 0.5

Z = norm.pdf(Y, beta0 + beta1*X, 1.0)

# Plot the surface with the "coolwarm" colormap

surf = ax.plot_surface(

X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,

linewidth=0, antialiased=False

)

# Set the limits of the z axis and major line locators

ax.set_zlim(0, 0.4)

ax.zaxis.set_major_locator(LinearLocator(5))

ax.zaxis.set_major_formatter(FormatStrFormatter(’%.02f’))

# Label all of the axes

ax.set_xlabel(’X’)

ax.set_ylabel(’Y’)

ax.set_zlabel(’P(Y|X)’)

# Adjust the viewing angle and axes direction

ax.view_init(elev=30., azim=50.0)

ax.invert_xaxis()

ax.invert_yaxis()

# Plot the probability density

plt.show()

The output is given in Figure 17.1.

The plot highlights how the expectation of the response y is linearly dependent upon x. The

"peak" of the distribution follows a linear path as x increases. The uncertainty associated with

the ɛ error of the model is represented by a normally-distributed spread around the peak for

each x. Notice in particular that the spread width does not change as x increases. This is a key

assumption used in linear regression models, namely that the variance does not increase with

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!