Plotting a linear regression function in 3D.

3 次查看(过去 30 天)
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 个评论
John D'Errico
John D'Errico 2019-10-14
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by