13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

239

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()

# lin_reg_sklearn.py

import matplotlib.pyplot as plt

import numpy as np

import seaborn as sns

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

Saved successfully!

Ooh no, something went wrong!