SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
WMBA 2008
       BITS: Serie Storiche in Matlab II

                      Emmanuele Somma
               emmanuele.somma@bancaditalia.it

               Supporto Informatico per l’Area Ricerche
                            Banca d’Italia


                        21 Gennaio 2008




E. Somma (SIA-BdI)           WMBA 2008              21/01/2008   1/43
Piano della presentazione

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   2/43
Preprocessing

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   3/43
Lettura dei dati

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   4/43
Vettore e time-series di dati
load count.dat
c3 = count(:,3)                    # VETTORE
t3 = tsmat(2007,1,4,c3)            # TIME SERIES
c3NaNCount = sum(isnan(c3))
ans =
       0
t3NanCount = sum(isnan(t3))
ans =
       0




          E. Somma (SIA-BdI)    WMBA 2008     21/01/2008   5/43
plot(c3);                            plot(t3)




        E. Somma (SIA-BdI)   WMBA 2008          21/01/2008   6/43
Missing e outliers

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   7/43
Outliers
bin_counts = hist(c3)           bin_counts = hist(t3.matdata)

# Massimo elemento
N = max(bin_counts);

# Media
mu3 = mean(c3);                 mu3 = mean(t3);

# Deviazione Std
sigma3 = std(c3);               sigma3 = std(c3);

hist(c3);                       hist(t3.matdata)




           E. Somma (SIA-BdI)      WMBA 2008       21/01/2008   8/43
hold on; X = repmat(mu3+(1:2)*sigma3,2,1);
Y = repmat([0;N],1,2);
plot([mu3 mu3],[0 N],’r’,’LineWidth’,2);
plot(X,Y,’g’,’LineWidth’,2)
legend(’Data’,’Mean’,’Stds’); hold off




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   9/43
outliers = (c3 - mu3) > 2*sigma3;
c3m = c3;
c3m(outliers) = NaN;

outliers = (t3 - mu3) > 2*sigma3;
t3m = t3;
t3m.matdata(outliers.matdata) = NaN;




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   10/43
bin_counts = hist(t3m.matdata); N = max(bin_counts);
hist(t3m.matdata); mu3 = nanmean(t3m); sigma3 = nanstd(t3m)
hold on; X = repmat(mu3+(1:2)*sigma3,2,1);
Y = repmat([0;N],1,2);
plot([mu3 mu3],[0 N],’r’,’LineWidth’,2);
plot(X,Y,’g’,’LineWidth’,2)
legend(’Data’,’Mean’,’Stds’); hold off




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008      11/43
Aggiustare e filtrare

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   12/43
Smoothing
plot(t3m,’o-’)
hold on




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   13/43
Smoothing
span = 3; % Ampiezza della finestra
window = ones(span,1)/span; smoothed_t3m = t3m
smoothed_t3m.matdata = convn(t3m.matdata,window,’same’);
h = plot(smoothed_t3m,’ro-’);




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008        14/43
Filtraggio
smoothed2_t3m = t3m;
smoothed2_t3m.matdata = filter(window,1,t3m.matdata);
plot(smoothed2_t3m,’go-’);
legend(’Data’,’Smoothed Data’,’Filtered Data’)




             E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   15/43
Misurazione

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   16/43
Misurazione dei dati
% Posizione                          % Scala
x1 = mean(t) ;                      dx1 = max(t)-min(t)
x2 = median(t) ;                    dx2 = std(t)
x3 = mode(t) ;                      dx3 = var(t)

                           % Forma
                           figure ; hist(t.matdata)




          E. Somma (SIA-BdI)       WMBA 2008     21/01/2008   17/43
Forma dei dati/1
    I modelli parametrici danno una rappresentazione analitica della forma
della distribuzione

t1 = tsmat(2007,1,4,count(:,1));
[bin_counts,bin_locations] = hist(t1.matdata);
bin_width = bin_locations(2) - bin_locations(1);
hist_area = (bin_width)*(sum(bin_counts));
figure
hist(t1.matdata)
hold on
mu1 = mean(t1);
exp_pdf = @(t)(1/mu1)*exp(-t/mu1);
t = 0:150;
y = exp_pdf(t);
plot(t,(hist_area)*y,’r’,’LineWidth’,2)
legend(’Distribution’,’Exponential Fit’)

          E. Somma (SIA-BdI)     WMBA 2008         21/01/2008           18/43
E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   19/43
Rappresentazione

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   20/43
Grafici 2D

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   21/43
Forma dei dati/2
t1 = tsmat(2007,1,4,count(:,1)); % Serie 1
t2 = tsmat(2007,1,4,count(:,2)); % Serie 2
figure
scatter(t1.matdata,t2.matdata,’filled’)
xlabel(’Intersection 1’)
ylabel(’Intersection 2’)




         E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   22/43
E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   23/43
Forma dei dati/2
C12 =   cov([t1 t2])      % Covarianza
R12 =   corrcoef([t1 t2])
r12 =   R12(1,2)          % Coefficiente di correlazione
r12sq   = r12^2           % Coefficiente di determinazione




          E. Somma (SIA-BdI)   WMBA 2008   21/01/2008        24/43
Grafici 3D

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   25/43
Forma dei dati/2
figure
scatter3(t1.matdata,t2.matdata,t3.matdata,’filled’)
xlabel(’Intersection 1’)
ylabel(’Intersection 2’)
zlabel(’Intersection 3’)




         E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   26/43
E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   27/43
La forza della relazione lineare tra le variabili ` misurata calcolando gli
                                                     e
autovalori della matrice di covarianza:

>> vars = eig(cov([t1 t2 t3]))
vars =
  1.0e+003 *
    0.0442
    0.1118
    6.8300

>> explained = max(vars)/sum(vars)
explained =
    0.9777

Gli autovalori sono le varianze lungo le componenti principali dei dati. La
variabile explained misura la proporzione della variazione spiegata dalla
prima componente principale lungo l’asse dei dati.

           E. Somma (SIA-BdI)     WMBA 2008          21/01/2008             28/43
Matrice di Grafici Scatter

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   29/43
E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   30/43
t = tsmat(2007,1,4,count)
figure
plotmatrix(t.matdata)




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   31/43
Modellazione

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   32/43
Regressione Polinomiale

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   33/43
t3 = tsmat(2007,1,4,count(:,3));        % Serie 3
tdata = [1:size(t3.dates,1)]’;
p_coeffs = polyfit(tdata,t3.matdata,6);
figure
plot(t3,’o-’)
hold on
n = ( max(tdata) / 6 ) / 365;
tfit = (1:n:24)’;
yfit = tsmat(2007,1,365,polyval(p_coeffs,tfit));
plot(yfit,’r-’)
legend(’Data’,’Polynomial Fit’,’Location’,’NW’)




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   34/43
E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   35/43
Regressione Lineare Generalizzata

1   Preprocessing
      Lettura dei dati
      Missing e outliers
      Aggiustare e filtrare

2   Misurazione

3   Rappresentazione
      Grafici 2D
      Grafici 3D
      Matrice di Grafici Scatter

4   Modellazione
     Regressione Polinomiale
     Regressione Lineare Generalizzata


           E. Somma (SIA-BdI)     WMBA 2008   21/01/2008   36/43
y = a + b cos((2π/12)(t − 7))

t3 = tsmat(2007,1,4,count(:,3)); % Serie 3
tdata = [1:size(t3.dates,1)]’;
X = [ones(size(tdata)) cos((2*pi/12)*(tdata-7))];
s_coeffs = Xt3.matdata;
figure
plot(t3,’o-’)
hold on
n = ( max(tdata) / 6 ) / 365;
tfit = (1:n:24)’;
yfit = [ones(size(tfit)) cos((2*pi/12)*(tfit-7))]*s_coeffs;
yt = tsmat(2007,1,365,yfit);
plot(yt,’r-’)
legend(’Data’,’Sinusoidal Fit’,’Location’,’NW’)


        E. Somma (SIA-BdI)         WMBA 2008        21/01/2008   37/43
E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   38/43
>> [s_coeffs,stdx,mse] = lscov(X,c3)
s_coeffs =
   65.5833
   73.2819

stdx =
    8.9185
   12.6127

mse =
  1.9090e+003




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   39/43
Fs = 1;             % Frequenza di campionamento
n = length(t3.matdata); % Lunghezza della finestra
Y = fft(t3.matdata);% DFT
f = (0:n-1)*(Fs/n); % Ampiezza della frequenza
P = Y.*conj(Y)/n;   % Potenza della DFT
figure
plot(f,P)
xlabel(’Frequency’)
ylabel(’Power’)
predicted_f = 1/12
predicted_f =
    0.0833




        E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   40/43
E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   41/43
Grazie dell’attenzione




E. Somma (SIA-BdI)   WMBA 2008   21/01/2008   42/43

Contenu connexe

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Workshop Matlab BITS Avanzato

  • 1. WMBA 2008 BITS: Serie Storiche in Matlab II Emmanuele Somma emmanuele.somma@bancaditalia.it Supporto Informatico per l’Area Ricerche Banca d’Italia 21 Gennaio 2008 E. Somma (SIA-BdI) WMBA 2008 21/01/2008 1/43
  • 2. Piano della presentazione 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 2/43
  • 3. Preprocessing 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 3/43
  • 4. Lettura dei dati 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 4/43
  • 5. Vettore e time-series di dati load count.dat c3 = count(:,3) # VETTORE t3 = tsmat(2007,1,4,c3) # TIME SERIES c3NaNCount = sum(isnan(c3)) ans = 0 t3NanCount = sum(isnan(t3)) ans = 0 E. Somma (SIA-BdI) WMBA 2008 21/01/2008 5/43
  • 6. plot(c3); plot(t3) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 6/43
  • 7. Missing e outliers 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 7/43
  • 8. Outliers bin_counts = hist(c3) bin_counts = hist(t3.matdata) # Massimo elemento N = max(bin_counts); # Media mu3 = mean(c3); mu3 = mean(t3); # Deviazione Std sigma3 = std(c3); sigma3 = std(c3); hist(c3); hist(t3.matdata) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 8/43
  • 9. hold on; X = repmat(mu3+(1:2)*sigma3,2,1); Y = repmat([0;N],1,2); plot([mu3 mu3],[0 N],’r’,’LineWidth’,2); plot(X,Y,’g’,’LineWidth’,2) legend(’Data’,’Mean’,’Stds’); hold off E. Somma (SIA-BdI) WMBA 2008 21/01/2008 9/43
  • 10. outliers = (c3 - mu3) > 2*sigma3; c3m = c3; c3m(outliers) = NaN; outliers = (t3 - mu3) > 2*sigma3; t3m = t3; t3m.matdata(outliers.matdata) = NaN; E. Somma (SIA-BdI) WMBA 2008 21/01/2008 10/43
  • 11. bin_counts = hist(t3m.matdata); N = max(bin_counts); hist(t3m.matdata); mu3 = nanmean(t3m); sigma3 = nanstd(t3m) hold on; X = repmat(mu3+(1:2)*sigma3,2,1); Y = repmat([0;N],1,2); plot([mu3 mu3],[0 N],’r’,’LineWidth’,2); plot(X,Y,’g’,’LineWidth’,2) legend(’Data’,’Mean’,’Stds’); hold off E. Somma (SIA-BdI) WMBA 2008 21/01/2008 11/43
  • 12. Aggiustare e filtrare 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 12/43
  • 13. Smoothing plot(t3m,’o-’) hold on E. Somma (SIA-BdI) WMBA 2008 21/01/2008 13/43
  • 14. Smoothing span = 3; % Ampiezza della finestra window = ones(span,1)/span; smoothed_t3m = t3m smoothed_t3m.matdata = convn(t3m.matdata,window,’same’); h = plot(smoothed_t3m,’ro-’); E. Somma (SIA-BdI) WMBA 2008 21/01/2008 14/43
  • 15. Filtraggio smoothed2_t3m = t3m; smoothed2_t3m.matdata = filter(window,1,t3m.matdata); plot(smoothed2_t3m,’go-’); legend(’Data’,’Smoothed Data’,’Filtered Data’) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 15/43
  • 16. Misurazione 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 16/43
  • 17. Misurazione dei dati % Posizione % Scala x1 = mean(t) ; dx1 = max(t)-min(t) x2 = median(t) ; dx2 = std(t) x3 = mode(t) ; dx3 = var(t) % Forma figure ; hist(t.matdata) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 17/43
  • 18. Forma dei dati/1 I modelli parametrici danno una rappresentazione analitica della forma della distribuzione t1 = tsmat(2007,1,4,count(:,1)); [bin_counts,bin_locations] = hist(t1.matdata); bin_width = bin_locations(2) - bin_locations(1); hist_area = (bin_width)*(sum(bin_counts)); figure hist(t1.matdata) hold on mu1 = mean(t1); exp_pdf = @(t)(1/mu1)*exp(-t/mu1); t = 0:150; y = exp_pdf(t); plot(t,(hist_area)*y,’r’,’LineWidth’,2) legend(’Distribution’,’Exponential Fit’) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 18/43
  • 19. E. Somma (SIA-BdI) WMBA 2008 21/01/2008 19/43
  • 20. Rappresentazione 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 20/43
  • 21. Grafici 2D 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 21/43
  • 22. Forma dei dati/2 t1 = tsmat(2007,1,4,count(:,1)); % Serie 1 t2 = tsmat(2007,1,4,count(:,2)); % Serie 2 figure scatter(t1.matdata,t2.matdata,’filled’) xlabel(’Intersection 1’) ylabel(’Intersection 2’) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 22/43
  • 23. E. Somma (SIA-BdI) WMBA 2008 21/01/2008 23/43
  • 24. Forma dei dati/2 C12 = cov([t1 t2]) % Covarianza R12 = corrcoef([t1 t2]) r12 = R12(1,2) % Coefficiente di correlazione r12sq = r12^2 % Coefficiente di determinazione E. Somma (SIA-BdI) WMBA 2008 21/01/2008 24/43
  • 25. Grafici 3D 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 25/43
  • 26. Forma dei dati/2 figure scatter3(t1.matdata,t2.matdata,t3.matdata,’filled’) xlabel(’Intersection 1’) ylabel(’Intersection 2’) zlabel(’Intersection 3’) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 26/43
  • 27. E. Somma (SIA-BdI) WMBA 2008 21/01/2008 27/43
  • 28. La forza della relazione lineare tra le variabili ` misurata calcolando gli e autovalori della matrice di covarianza: >> vars = eig(cov([t1 t2 t3])) vars = 1.0e+003 * 0.0442 0.1118 6.8300 >> explained = max(vars)/sum(vars) explained = 0.9777 Gli autovalori sono le varianze lungo le componenti principali dei dati. La variabile explained misura la proporzione della variazione spiegata dalla prima componente principale lungo l’asse dei dati. E. Somma (SIA-BdI) WMBA 2008 21/01/2008 28/43
  • 29. Matrice di Grafici Scatter 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 29/43
  • 30. E. Somma (SIA-BdI) WMBA 2008 21/01/2008 30/43
  • 31. t = tsmat(2007,1,4,count) figure plotmatrix(t.matdata) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 31/43
  • 32. Modellazione 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 32/43
  • 33. Regressione Polinomiale 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 33/43
  • 34. t3 = tsmat(2007,1,4,count(:,3)); % Serie 3 tdata = [1:size(t3.dates,1)]’; p_coeffs = polyfit(tdata,t3.matdata,6); figure plot(t3,’o-’) hold on n = ( max(tdata) / 6 ) / 365; tfit = (1:n:24)’; yfit = tsmat(2007,1,365,polyval(p_coeffs,tfit)); plot(yfit,’r-’) legend(’Data’,’Polynomial Fit’,’Location’,’NW’) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 34/43
  • 35. E. Somma (SIA-BdI) WMBA 2008 21/01/2008 35/43
  • 36. Regressione Lineare Generalizzata 1 Preprocessing Lettura dei dati Missing e outliers Aggiustare e filtrare 2 Misurazione 3 Rappresentazione Grafici 2D Grafici 3D Matrice di Grafici Scatter 4 Modellazione Regressione Polinomiale Regressione Lineare Generalizzata E. Somma (SIA-BdI) WMBA 2008 21/01/2008 36/43
  • 37. y = a + b cos((2π/12)(t − 7)) t3 = tsmat(2007,1,4,count(:,3)); % Serie 3 tdata = [1:size(t3.dates,1)]’; X = [ones(size(tdata)) cos((2*pi/12)*(tdata-7))]; s_coeffs = Xt3.matdata; figure plot(t3,’o-’) hold on n = ( max(tdata) / 6 ) / 365; tfit = (1:n:24)’; yfit = [ones(size(tfit)) cos((2*pi/12)*(tfit-7))]*s_coeffs; yt = tsmat(2007,1,365,yfit); plot(yt,’r-’) legend(’Data’,’Sinusoidal Fit’,’Location’,’NW’) E. Somma (SIA-BdI) WMBA 2008 21/01/2008 37/43
  • 38. E. Somma (SIA-BdI) WMBA 2008 21/01/2008 38/43
  • 39. >> [s_coeffs,stdx,mse] = lscov(X,c3) s_coeffs = 65.5833 73.2819 stdx = 8.9185 12.6127 mse = 1.9090e+003 E. Somma (SIA-BdI) WMBA 2008 21/01/2008 39/43
  • 40. Fs = 1; % Frequenza di campionamento n = length(t3.matdata); % Lunghezza della finestra Y = fft(t3.matdata);% DFT f = (0:n-1)*(Fs/n); % Ampiezza della frequenza P = Y.*conj(Y)/n; % Potenza della DFT figure plot(f,P) xlabel(’Frequency’) ylabel(’Power’) predicted_f = 1/12 predicted_f = 0.0833 E. Somma (SIA-BdI) WMBA 2008 21/01/2008 40/43
  • 41. E. Somma (SIA-BdI) WMBA 2008 21/01/2008 41/43
  • 42. Grazie dell’attenzione E. Somma (SIA-BdI) WMBA 2008 21/01/2008 42/43