Sumerechny
Sumerechny

Reputation: 168

Fault in 3D wireframe plot of polynomial regression and optimization

I'm would like to plot a 3d wireframe using of a x,y, z-prediction all with a length of 2048. Even though I'm quite happy with the code I wrote, the plot is not quite right. There are comparable faults related to 2D plot's but I'm having trouble translating this to my 3D approach.

Who is willing to provide me with a short push in the right direction?

import matplotlib.pyplot as plt

X, Y = np.meshgrid(calibration_matrix['exposure'],calibration_matrix['row'])

if z_pred==None:
Z_pred = np.zeros(X.shape)
for idx in np.ndindex(X.shape):
    Z_pred[idx] = regression_model.predict(poly.fit_transform(np.array([X[idx], Y[idx]]).reshape(1, -1)))  

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.plot_wireframe(X, Y, Z_pred, rstride=20, cstride=20)
plt.show()

A short additional question; Given the size of the dataset the calculation takes relatively long. I'm thinking about limiting the time needed by sparse sampling, is this in line with normal convention?

Edit: The first plot below is the current result, but I'm looking for something comparable to the second (not the shape or points from the scatterplot section, just the mesh and not the interlocking lines across the base):

enter image description here

enter image description here

Upvotes: 0

Views: 38

Answers (1)

Sumerechny
Sumerechny

Reputation: 168

I took some steps back and rebuilt the code. The most important change is the prediction of y_wireframe from the original X and Z np.meshgrid.

X, Z = np.meshgrid(X_arr, Z_arr)
Y = regression_model.predict(poly.fit_transform(np.array([X.ravel(), Z.ravel()]).T)).reshape(X.shape)

In which X and Z are fixed 100 * 100 arrays build from np.linspace.

The result, though not perfect is in line with what I had in mind.

enter image description here

Thank you for your help @manu190466

Upvotes: 0

Related Questions