• Non ci sono risultati.

y_train = x_train.^2+3

N/A
N/A
Protected

Academic year: 2021

Condividi "y_train = x_train.^2+3"

Copied!
7
0
0

Testo completo

(1)

clear all, clc,  

x_train = -5:0.25:5;

x_test = -5.1:0.25:4.9;

 y_train = x_train.^2+3;

y_test = x_test.^2+3;

 

figure,

plot(x_train,y_train); xlim([-8,8]);

title('Model');

xlabel('X'), ylabel('Y');

 

y_train = y_train + 2*randn(1,length(y_train));

y_test = y_test + 2*randn(1,length(y_test));

 

figure;

subplot(1,2,1)

plot(x_train,y_train,'*'); xlim([-8,8]);

title('Data for training the estimator');

xlabel('X'), ylabel('Y');

 

subplot(1,2,2)

plot(x_test,y_test,'*'); xlim([-8,8]);

(2)

xlabel('X'), ylabel('Y');

 

% Train and test of several estimators  

degree = [1 2 3 10 15 20 22];

 

for i = 1:length(degree)    

  N = degree(i);

  P = polyfit(x_train,y_train,N);

  y_N = polyval(P,x_train);

     figure,

  plot(x_train,y_train,'*'), xlim([-10,10]),   title(strcat('Degree:',{' '},num2str(N)) );

  xlabel('X'), ylabel('Y');

  hold on;

  plot(x_train,y_N);

   

  err_train(i) = rms( polyval(P,x_train) - y_train );

  err_test(i) = rms( polyval(P,x_test) - y_test );

   end

(3)
(4)

Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT.

(5)

Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT.

Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of

(6)

 

figure;

plot(1:length(degree),err_train,'-*');

hold on

plot(1:length(degree),err_test,'-*');

 

xticklabels({'1','2','3','10','15','20','25'});

xlabel('Degree'), ylabel('RMSE');

 

legend('Train','Test');

(7)

 

Riferimenti

Documenti correlati

Continuum Limit, Finite Size Scaling, Lindeberg Principle, Polynomial Chaos, Wiener Chaos, Disordered Pinning Model, Directed Polymer Model, Random Field Ising

• asymptotic spacing in the multivariate case (cf. [7]): then we look for an approximate solution; surprisingly, this can be obtained by basic numerical linear algebra.. we compute

Educational widget that interactively shows regression line for different

Find the coefficients of the polynomial interpolating x = (−2, 1, 3) and y = (−2, 11, 17) via the polyfit command on a script named. Esercizio2 and

The process of vortex cascade through continuous reduction of topological complexity by stepwise unlinking, that has been observed experimentally in the production of vortex

Govil [4] extended the inequality (1.3) to an inequality involving moduli of all the zeros of a complex polynomial rather than restricting only to the zero of maximum

Remove repeated data points or try centering and scaling as described in HELP POLYFIT.. Remove repeated data points or try centering and scaling as described in

Remove repeated data points or try centering and scaling as described in HELP POLYFIT.. Remove repeated data points or try centering and scaling as described in