Question
Can you please help me solve my error. Create Second Image Use the following x_fit and y_fit data to compute z_fit by invoking the model's
Can you please help me solve my error.
Create Second Image
Use the following x_fit and y_fit data to compute z_fit by invoking the model's predict() method. This will allow you to plot the line of best fit that is predicted by the model.
This is my code so far:
from sklearn.linear_model import LinearRegression
training_data = poly_reg[['x', 'y']] response = poly_reg['z']
#Instantiate LinearReg object model = LinearRegression() #Fit the model to the data model.fit(pol_feat, y)
from sklearn.linear_model import LinearRegression
training_data = poly_reg[['x', 'y']] response = poly_reg['z']
#Instantiate LinearReg object model = LinearRegression() #Fit the model to the data model.fit(pol_feat, y)
from sklearn.linear_model import LinearRegression
fig, axs = plt.subplots(2, 2, figsize=(15, 10), subplot_kw={'projection': '3d'}) axs = axs.ravel()
#data for reg line model = LinearRegression(fit_intercept = True) #not sure model.fit(pol_feat, y) x_fit = np.linspace(-21,21,1000) y_fit = x_fit
#creating a new dataframe from x_fit and y_fit to be features x_fit1 = pd.Series(x_fit) y_fit1 = pd.Series(y_fit) xy_fit = pd.concat([x_fit1, y_fit1],axis=1) zfit = model.predict(xy_fit)
#changing fit array to series to be used in plots below fit_x = pd.Series(x_fit) fit_y = pd.Series(y_fit) fit_z = pd.Series(zfit)
#Image for scatterplot 1 axs[0].scatter3D(x,y,z,c=z, cmap='jet') axs[0].set_xlabel('x', c='r', size =12) axs[0].set_ylabel('y', c='r', size =12) axs[0].set_zlabel('z', c='r', size =12) axs[0].view_init(1,86)
#plotline fig 1 axs[0].plot3D(x,y,z, color='black', linewidth=2)
#Image for scatterplot 2 axs[1].scatter3D(x,y,z,c=z, cmap='jet') axs[1].set_xlabel('x', c='r', size =12) axs[1].set_ylabel('y', c='r', size =12) axs[1].set_zlabel('z', c='r', size =12) axs[1].view_init(90,0)
#plotline fig 2 axs[1].plot3D(x,y,z, color='black', linewidth=2)
#Image for scatterplot 3 axs[2].scatter3D(x,y,z,c=z, cmap='jet') axs[2].set_xlabel('x', c='r', size =12) axs[2].set_ylabel('y', c='r', size =12) axs[2].set_zlabel('z', c='r', size =12) axs[2].view_init(37,46)
#plotline fig 3 axs[2].plot3D(x,y,z, color='black', linewidth=2)
#Image for scatterplot 4 axs[3].scatter3D(x,y,z,c=z, cmap='jet') axs[3].set_xlabel('x', c='r', size =12) axs[3].set_ylabel('y', c='r', size =12) axs[3].set_zlabel('z', c='r', size =12) axs[3].view_init(17,81)
#plotline fig 4 axs[3].plot3D(x,y,z, color='black', linewidth=2)
plt.show()
This is the error
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started