How to generate polynomial matrix in classification problems ?

1 Ansicht (letzte 30 Tage)
Abdelwahab Afifi
Abdelwahab Afifi am 18 Mär. 2020
Bearbeitet: Abdelwahab Afifi am 20 Mär. 2020
I have the fllowing samples [1 2] , [2 0] , [1 1], [3 1], [2 3], [3 3] which correspond to labels y : {0, 0, 0, 1, 1, 1} respectively. Our goal is to predict the class label of xt1=[4 1] and xt2=[1 0] .
I already simulate the 3) MSE using indicator Matrix as follow:
clc; clear all; close all;
s1=[1 2];
s2=[2 0];
s3=[1 1];
s4=[3 1];
s5=[2 3];
s6=[3 3];
S=[s1;s2;s3;s4;s5;s6];
xt1=[4 1];
xt2=[1 0];
disp('MSE using Indicator Matrix (Primal)')
X=Xo
Y=[ones(3,1) zeros(3,1);zeros(3,1) ones(3,1)]
w=inv(X'*X)*X'*Y
predict1=[1 xt1]*w
predict2=[1 xt2]*w
predict=[1 xt1; 1 xt2]*w
However, in case of MSE with polynomial, how can I calculate matrix P in case of 2'nd order and 3'rd order polynomial ?! to get the same results. I tried the following code, but can't obtain the same results.
% MSE with Polynomial (Dual)
X=[ones(6,1) S S.^2 S(:,1).*S(:,2)]
Y=[ones(3,1) zeros(3,1);zeros(3,1) ones(3,1)]
w=X'*inv(X*X')*Y % Dual
predict1=[1 xt1 xt1.^2 xt1(1)*xt1(2)]*w
predict1=[1 xt2 xt2.^2 xt2(1)*xt2(2)]*w

Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by