Weird 3D Scatterplot results
Archiviert 2 months ago
T
Tsunami 🌊
Verified
The first image has this code attached to it:
```filenameLR2 = 'LR2-1.xlsx'
data_LR2 = pd.read_excel(filenameLR2)
XY = data_LR2[['X', 'Y']].values
Z = data_LR2['Z'].values
model=LinearRegression()
model.fit(XY,Z)
print("Model Coefficients: ", model.coef_)
print("Model Intercept : ", model.intercept_)
model.score(XY, Z)
x_fit = np.linspace(0, 21, 5000)
y_fit = x_fit
z_fit = model.predict(np.column_stack((x_fit, y_fit)))
fig = plt.figure(figsize = (16, 9))
ax = plt.axes(projection ="3d")
X,Y = np.meshgrid(x_fit, y_fit)
Z = 0.54079386*X + 0.39793276*Y - 30.477902526663
ax.scatter3D(data_LR2['X'], data_LR2['Y'], data_LR2['Z'])
ax.plot(x_fit, y_fit, z_fit, color='red')
ax.plot_surface(X,Y,Z, color='red', alpha = 0.4)
plt.title("simple 3D scatter plot")
ax.set_xlabel('X-axis', fontweight ='bold')
ax.set_ylabel('Y-axis', fontweight ='bold')
ax.set_zlabel('Z-axis', fontweight ='bold')
plt.show()```
And I'm trying to replicate what the second image (example) looks like but it keeps turning into this weird straight line.

