Plotting a linear regression function in 3D.

조회 수: 14 (최근 30일)
johnny2
johnny2 2019년 10월 14일
댓글: John D'Errico 2019년 10월 14일
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