In [5]: x_fit = np.linspace(0,21,1000) y_fit = x_fit #Reshape the x fit and y_fit... x_fit = x_fit.reshape(-1,1) y_fit = y_fit.reshape(-1,1) #Fit the model on x fit and y_fit... model.fit(x_fit, y_fit) #Now, merge the x fit and y_fit as dataframe... mixData = pd.DataFrame({'x': [x_fit], 'y': [y_fit]}) #Now, use the predict() method to find the z_fit using the above dataframe... z_fit = model.predict (mixData['x'][0]) Recreate the first image, but plot the line of best fit in each of the subplots as well. In [9]: fig-plt.figure(figsize=[10,10]) #==‒‒‒‒‒‒‒========= # First subplot ======= #set up the axes for the first plot ax1 = fig.add_subplot (2, 2, 1, projection="3d") ax1.scatter(dfData['x'], dfData['y'],dfData['z'],c=dfData['z'],cmap='jet') ax1.set_xlabel('x', fontsize=9) axl.set_ylabel('y', fontsize=9) axl.set_zlabel('z', fontsize=9) axi.view_init(9, 90) start, end = ax1.get_xlim() axi.xaxis.set_ticks(np.arange(0, end, 5)) start2, end2 = axi.get_ylim() axi.yaxis.set_ticks(np.arange(0, end2, 5)) font = {'size': 8} axi.tick_params ('x', labelsize-font['size']) axi.tick_params ('y', labelsize-font['size']) axi.tick_params ('z', labelsize-font['size']) axi.plot3d(x_fit, z_fit, c='black')
In [5]: x_fit = np.linspace(0,21,1000) y_fit = x_fit #Reshape the x fit and y_fit... x_fit = x_fit.reshape(-1,1) y_fit = y_fit.reshape(-1,1) #Fit the model on x fit and y_fit... model.fit(x_fit, y_fit) #Now, merge the x fit and y_fit as dataframe... mixData = pd.DataFrame({'x': [x_fit], 'y': [y_fit]}) #Now, use the predict() method to find the z_fit using the above dataframe... z_fit = model.predict (mixData['x'][0]) Recreate the first image, but plot the line of best fit in each of the subplots as well. In [9]: fig-plt.figure(figsize=[10,10]) #==‒‒‒‒‒‒‒========= # First subplot ======= #set up the axes for the first plot ax1 = fig.add_subplot (2, 2, 1, projection="3d") ax1.scatter(dfData['x'], dfData['y'],dfData['z'],c=dfData['z'],cmap='jet') ax1.set_xlabel('x', fontsize=9) axl.set_ylabel('y', fontsize=9) axl.set_zlabel('z', fontsize=9) axi.view_init(9, 90) start, end = ax1.get_xlim() axi.xaxis.set_ticks(np.arange(0, end, 5)) start2, end2 = axi.get_ylim() axi.yaxis.set_ticks(np.arange(0, end2, 5)) font = {'size': 8} axi.tick_params ('x', labelsize-font['size']) axi.tick_params ('y', labelsize-font['size']) axi.tick_params ('z', labelsize-font['size']) axi.plot3d(x_fit, z_fit, c='black')
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
How do I get the line of best fit plotted in my 3D scatterplot in Matlibplot? I am trying to use "plot3d()" but I do not know what to put in the paretheses? To be clear, we HAVE to use x_fit, y_fit and z_fit. Please look at my code and let me know how to get the line plotted in the scatterplot I created - because as you can see, I tried "ax.plot3d(x_fit, z_fit,c='black') but that does not work for me.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
I need the line to be a thin black line so the scatterplot does not "disappear". How to I format it?
Solution
by Bartleby Expert
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY