Plotting a linear regression function in 3D.

21 views (last 30 days)
johnny2
johnny2 on 14 Oct 2019
Commented: John D'Errico on 14 Oct 2019
I have two feature vectors that I need to plot on the x and y axis and a label that I need to plot on the z axis. I've gotten as far as calculating the learned function but I can't seem to plot it properly. I am using data from the winer_dataset provided by matlab. My features are magnesium and color intensity and my labels are the winery. I've tried using fsurf to plot but to no avail. Can someone please look at my code and help me find a solution? Thanks!
%Remove all rows corresponding to the labelled winery 3
P = A; % A is the matrix of all the winery and labels provided by wine_dataset in matlab
P(131:178, :) = []; %I only want to use winerys 1 and 2, so I got rid of all the rows for winery 3
x1 = P(:,5); %x1 is magnesium
x2 = P(:,10); %x2 is color intensity
Y = P(:,14); %Y is the winery labelled 1-2
%plot the two features and their corresponding label
plot3(x1, x2, Y, 'o');
hold on
X = [ones(130,1), x1, x2];
%calculating w
w = X\Y; %w = X\Y solves the symbolic system of linear equations in matrix form, X*w = Y for w.
%calculating y
y = X * w;
%z = @(x1, x2) y;
plot3(x1, x2, y);
%fsurf(z);
  1 Comment
John D'Errico
John D'Errico on 14 Oct 2019
If the X & Y matrices are themselves numeric, then w = X\Y is NOT a symbolic solve! It is a numerical solve that uses linear algebra.

Sign in to comment.

Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!