gl.plot(lags, residuals) ########################################################## # Plotting of the regression plotting_3D = 1 if (plotting_3D): # Y_data = np.sign(Y_data) gl.scatter_3D(X_data[:, 0], X_data[:, 1], Y_data, labels=["", "", ""], legend=["Pene"], nf=1) grids = ul.get_grids(X_data) z = bMA.get_plane_Z(grids[0], grids[1], params) h = gl.plot_3D(grids[0], grids[1], z, nf=0) ################################### ##### TODO ##################3 ################################## # How it would be to take reconstruct from the diff signal # We shift to the right to that # v[i] = x[i] - x[i-1] and x[i] # If we do v[j] = v[i+1] = x[i+1] - x[i] # Then v[j] + x[i] = x[i+1] # So then we shift to the left #vel_shifted = np.roll(MACD_vel[:,[indx]],-1, axis = 0)
# labels = ["slices of the joint distribution","X_1","X_2"], alpha = 0.2) # Y = A.dot(X) # ax3D = gl.scatter_3D(Y[0,:], Y[1,:], Y[2,:], nf = 0, # labels = ["slices of the joint distribution","X_1","X_2"], alpha = 0.6) ######## DRAWING THE HYPERPLANE ######### v = R[0,:] nx = 1 grid_x = np.linspace(-nx,nx,20) grid_y = np.linspace(-nx,nx,20) params = [0, -v[0]/v[2], -v[1]/v[2]] zz = bMA.get_plane_Z(grid_x, grid_y, params) xx, yy = np.meshgrid(grid_x, grid_y, sparse=True) ax3D = gl.plot_3D(xx, yy, zz, nf = 0, labels = ["slices of the joint distribution","X_1","X_2"], alpha = 0.8) #### Plotting the vectors nx = 5 v = R[0,:] ax3D.plot([-nx*v[0], nx*v[0]],[-nx*v[1], nx*v[1]],[-nx*v[2], nx*v[2]], lw = 3) v = R[1,:] ax3D.plot([-nx*v[0], nx*v[0]],[-nx*v[1], nx*v[1]],[-nx*v[2], nx*v[2]], lw = 3) v = R[2,:] ax3D.plot([-nx*v[0], nx*v[0]],[-nx*v[1], nx*v[1]],[-nx*v[2], nx*v[2]], lw = 3) # ax3D.axis('equal') # ax.plot_wireframe(x, y, z, rstride=4, cstride=4, color='b', alpha=0.2)
gl.plot(lags, residuals) ############## Plotting of 3D regression ############## plotting_3D = 1 if (plotting_3D): # We train 3 models # Y_data = np.sign(Y_data) mask_X = np.sum(np.isnan(X_data), axis = 1) == 0 mask_Y = np.isnan(Y_data) == 0 mask = mask_X & mask_Y[:,0] # Mask without NaNs. This is done automatically in the OLS # Create linear regression object regr = linear_model.LinearRegression() # Train the model using the training sets X_datafiltered = X_data[:,[0,1]] regr.fit(X_datafiltered[mask,:], Y_data[mask,:]) # coeffs = np.array([regr.intercept_, regr.coef_])[0] coeffs = np.append(regr.intercept_, regr.coef_) params = np.array(coeffs) gl.scatter_3D(X_data[:,0],X_data[:,1], Y_data, labels = ["","",""], legend = ["Pene"], nf = 1) grids = ul.get_grids(X_data) z = bMA.get_plane_Z(grids[0], grids[1],params) h = gl.plot_3D(grids[0],grids[1],z, nf = 0)