You are on page 1of 34

FINAL EXAMINATION OF ENGINEERING STATISTIC

Summary of receipts, outlays, and


surpluses or deficits in current dollars,
constant (FY 2005), and as percentages of
GDP

Lecture :

by

INDUSTRIAL ENGINEERING UNDERGRADUATE PROGRAM

TANGERANG
2017

1
Table of Contents

Import data from Spreadsheet ........................................................................................................... 3


Import the data...................................................................................................................................... 3
Create output Variable......................................................................................................................... 3
Allocate Imported Array to Column Variable Names ...................................................................... 3
Clear Temporary Variables ................................................................................................................. 3
I. Visualization – How can I see what my data show ? .............................................................. 4
1. Bar ............................................................................................................................................... 4
2. Hist .............................................................................................................................................. 6
3. Boxplot........................................................................................................................................ 8
II. Resampling – How do I estimate the uncertainty of my measures? .................................. 11
1. Dfittool Outlays ........................................................................................................................ 11
2. Dfittool Receipts ....................................................................................................................... 16
III. Distributions – How do I estimate the uncertainty of my measures ? ............................ 23
1. median, mean, std, mode, skewness, kurtosis Outlays.............................................................. 23
2. median, mean, std, mode, skewness, kurtosis Receipts ............................................................ 24
IV. The Linear Model – How can I create a simple model of my data ? .............................. 24
V. Machine Learning : Classification ............................................................................................ 27
VI. Machine Learning : Curve Fitting ......................................................................................... 28

CREATED NOVEMBER 2017 ========================================================

2
Import data from Spreadsheet
% DESCRIPTIVE TEXTImport data from spreadsheet
% Script for importing data from the following spreadsheet:
%
% Workbook: D:\02. S1 Industrial Engineering SGU\02. Engineering
% Statistic\MATLAB\Receipts and Outlays.xlsx Worksheet: Sheet1
%
% To extend the code for use with different selected data or a different
% spreadsheet, generate a function instead of a script.

% Auto-generated by MATLAB on 2017/11/02 20:55:17

Import the data


%% Import the data
[~, ~, raw] = xlsread('D:\02. S1 Industrial Engineering SGU\02. Engineering
Statistic\MATLAB\Receipts and Outlays.xlsx','Sheet1','C5:F80');

Create output Variable


%% Create output variable
data = reshape([raw{:}],size(raw));

Allocate Imported Array to Column Variable Names


%% Allocate imported array to column variable names
Year = data(:,1);
Outlays = data(:,2);
Receipts = data(:,3);
SurplusorDeficit = data(:,4);

Clear Temporary Variables


%% Clear temporary variables
clearvars data raw;

3
I. Visualization – How can I see what my data show ?
1. Bar

%% Grafik Batang Outlays


%CREATEFIGURE(XVECTOR1, YVECTOR1)
% XVECTOR1: bar xvector
% YVECTOR1: bar yvector

% Auto-generated by MATLAB on 02-Nov-2017 22:32:52

% Create figure
figure1 = figure;

% Create axes
axes1 = axes('Parent',figure1);
box(axes1,'on');
hold(axes1,'all');

% Create bar
bar(Year,Outlays);

% Create xlabel
xlabel('Tahun');

% Create ylabel
ylabel('Outlays %');

% Create title
title('Grafik Outlays');

4
% Melalui grafik batang, kita dapat melihat data ‘Outlays’ secara individual.
Dari grafik di atas terlihat rentang data tahun 1944-1946, US memiliki “%
Outlays” yang tinggi dibandingkan tahun-tahun lainnya.

%% Grafik Batang Receipts

%CREATEFIGURE(XVECTOR1, YVECTOR1)
% XVECTOR1: bar xvector
% YVECTOR1: bar yvector

% Auto-generated by MATLAB on 02-Nov-2017 22:32:52

% Create figure
figure2 = figure;

% Create axes
axes2 = axes('Parent',figure2);
box(axes2,'on');
hold(axes2,'all');

% Create bar
bar(Year,Receipts);

% Create xlabel
xlabel('Tahun');

% Create ylabel
ylabel('Receipts %');

% Create title
title('Grafik Receipts');

5
% Melalui grafik batang, kita dapat melihat data ‘Receipts’ secara
individual. Dari grafik di atas terlihat rentang data tahun 1940-1944, US
memiliki “% Receipts” yang rendah dibandingkan tahun-tahun lainnya.

2. Hist
%CREATEFIGURE(VERTEXNORMALS1, YDATA1, XDATA1, VERTICES1, FACES1,
FACEVERTEXCDATA1, CDATA1)
% VERTEXNORMALS1: patch vertexnormals
% YDATA1: patch ydata
% XDATA1: patch xdata
% VERTICES1: patch vertices
% FACES1: patch faces
% FACEVERTEXCDATA1: patch facevertexcdata
% CDATA1: patch cdata

% Auto-generated by MATLAB on 05-Nov-2017 19:30:44

% Create figure
figure1 = figure;

% Create axes
axes1 = axes('Parent',figure1,'CLim',[1 2]);
box(axes1,'on');

% Create patch
patch('Parent',axes1,'VertexNormals',VertexNormals1,'YData',YData1,...
'XData',XData1,...
'Vertices',Vertices1,...
'Faces',Faces1,...

6
'FaceColor','flat',...
'FaceVertexCData',FaceVertexCData1,...
'DisplayName','Outlays',...
'CData',CData1);

% Create title
title('Histogram Outlays');

% Melalui grafik histogram, kita dapat melihat distribusi data ‘Outlays’.


Dari grafik di atas terlihat distribusi “% Outlays” US paling banyak,berada
pada range 15-25% GDP.

%CREATEFIGURE1(VERTEXNORMALS1, YDATA1, XDATA1, VERTICES1, FACES1,


FACEVERTEXCDATA1, CDATA1)
% VERTEXNORMALS1: patch vertexnormals
% YDATA1: patch ydata
% XDATA1: patch xdata
% VERTICES1: patch vertices
% FACES1: patch faces
% FACEVERTEXCDATA1: patch facevertexcdata
% CDATA1: patch cdata

% Auto-generated by MATLAB on 05-Nov-2017 19:37:37

% Create figure
figure1 = figure;

% Create axes
axes1 = axes('Parent',figure1,'CLim',[1 2]);
box(axes1,'on');

7
% Create patch
patch('Parent',axes1,'VertexNormals',VertexNormals1,'YData',YData1,...
'XData',XData1,...
'Vertices',Vertices1,...
'Faces',Faces1,...
'FaceColor','flat',...
'FaceVertexCData',FaceVertexCData1,...
'DisplayName','Receipts',...
'CData',CData1);

% Create title
title('Histogram Receipts');

% Melalui grafik histogram, kita dapat melihat distribusi data ‘Receipts’.


Dari grafik di atas terlihat distribusi “% Receipts” US paling banyak,berada
pada range 16-20% GDP.

3. Boxplot
XData3, YData5, XData4, YData6, YData7, YData8, XData5, YData9, XData6,
YData10, XData7, YData11, XData8, YData12, XData9, YData13, XData10,
YData14)
%CREATEFIGURE1(XDATA1, YDATA1, XDATA2, YDATA2, YDATA3, YDATA4, XDATA3,
YDATA5, XDATA4, YDATA6, YDATA7, YDATA8, XDATA5, YDATA9, XDATA6, YDATA10,
XDATA7, YDATA11, XDATA8, YDATA12, XDATA9, YDATA13, XDATA10, YDATA14)
% XDATA1: line xdata
% YDATA1: line ydata
% XDATA2: line xdata
% YDATA2: line ydata
% YDATA3: line ydata
% YDATA4: line ydata

8
% XDATA3: line xdata
% YDATA5: line ydata
% XDATA4: line xdata
% YDATA6: line ydata
% YDATA7: line ydata
% YDATA8: line ydata
% XDATA5: line xdata
% YDATA9: line ydata
% XDATA6: line xdata
% YDATA10: line ydata
% XDATA7: line xdata
% YDATA11: line ydata
% XDATA8: line xdata
% YDATA12: line ydata
% XDATA9: line xdata
% YDATA13: line ydata
% XDATA10: line xdata
% YDATA14: line ydata

% Auto-generated by MATLAB on 05-Nov-2017 20:03:12

% Create figure
figure1 = figure;

% Create axes
axes1 = axes('Parent',figure1,'XTickLabel','','XTick',zeros(1,0));
%% Uncomment the following line to preserve the X-limits of the axes
% xlim(axes1,[0.5 2.5]);
%% Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[4.96 45.44]);
box(axes1,'on');

% Create hggroup
hggroup1 = hggroup('Parent',axes1);

% Create line
line(XData1,YData1,'Parent',hggroup1,'Tag','Upper Whisker','LineStyle','--
');

% Create line
line(XData2,YData2,'Parent',hggroup1,'Tag','Upper Whisker','LineStyle','--
');

% Create line
line(XData1,YData3,'Parent',hggroup1,'Tag','Lower Whisker','LineStyle','--
');

% Create line
line(XData2,YData4,'Parent',hggroup1,'Tag','Lower Whisker','LineStyle','--
');

% Create line
line(XData3,YData5,'Parent',hggroup1,'Tag','Upper Adjacent Value');

% Create line
line(XData4,YData6,'Parent',hggroup1,'Tag','Upper Adjacent Value');

% Create line
line(XData3,YData7,'Parent',hggroup1,'Tag','Lower Adjacent Value');

9
% Create line
line(XData4,YData8,'Parent',hggroup1,'Tag','Lower Adjacent Value');

% Create line
line(XData5,YData9,'Parent',hggroup1,'Tag','Box','Color',[0 0 1]);

% Create line
line(XData6,YData10,'Parent',hggroup1,'Tag','Box','Color',[0 0 1]);

% Create line
line(XData7,YData11,'Parent',hggroup1,'Tag','Median','Color',[1 0 0]);

% Create line
line(XData8,YData12,'Parent',hggroup1,'Tag','Median','Color',[1 0 0]);

% Create line
line(XData9,YData13,'Parent',hggroup1,'Tag','Outliers',...
'MarkerEdgeColor',[1 0 0],...
'Marker','+',...
'LineStyle','none',...
'Color',[0 0 1]);

% Create line
line(XData10,YData14,'Parent',hggroup1,'Tag','Outliers',...
'MarkerEdgeColor',[1 0 0],...
'Marker','+',...
'LineStyle','none',...
'Color',[0 0 1]);

% Create text
text('Parent',hggroup1,'VerticalAlignment','bottom','Interpreter','none',..
.
'Units','points',...
'String','1',...
'Position',[81.375 -13.5 0],...
'HorizontalAlignment','center');

% Create text
text('Parent',hggroup1,'VerticalAlignment','bottom','Interpreter','none',..
.
'Units','points',...
'String','2',...
'Position',[244.125 -13.5 0],...
'HorizontalAlignment','center');

% Create title
title('Outlays-Receipts Boxplot');

10
% Melalui grafik boxplot, kita dapat melihat outliers dari data ‘Outlays’
dan data ‘Receipts’. Outlier untuk data Outlays ada 6 data. Nilai maksimum
data 43.6, minimum 9.8, jumlah titik 76, lower adjacent 14.2, upper adjacent
25.4 sedangkan outlier untuk data Receipts ada 11 data. Nilai maksimum data
20.9, minimum 6.8, jumlah titik 76, lower adjacent 16.1, upper adjacent 19.9.

II. Resampling – How do I estimate the uncertainty of my


measures?

1. Dfittool Outlays

11
12
function pd1 = createFit(Outlays)
%CREATEFIT Create plot of datasets and fits
% PD1 = CREATEFIT(OUTLAYS)
% Creates a plot, similar to the plot in the main distribution fitting
% window, using the data that you provide as input. You can
% apply this function to the same data you used with dfittool
% or with different data. You may want to edit the function to
% customize the code and this help message.
%
% Number of datasets: 1
% Number of fits: 1
%
% See also FITDIST.

% This function was automatically generated on 05-Nov-2017 20:45:49

% Output fitted probablility distribution: PD1

% Data from dataset "Outlays data":


% Y = Outlays

% Force all inputs to be column vectors

13
Outlays = Outlays(:);

% Prepare figure
clf;
hold on;
LegHandles = []; LegText = {};

% --- Plot data originally in dataset "Outlays data"


[CdfF,CdfX] = ecdf(Outlays,'Function','cdf'); % compute empirical cdf
BinInfo.rule = 1;
[~,BinEdge] = internal.stats.histbins(Outlays,[],[],BinInfo,CdfF,CdfX);
[BinHeight,BinCenter] = ecdfhist(CdfF,CdfX,'edges',BinEdge);
hLine = bar(BinCenter,BinHeight,'hist');
set(hLine,'FaceColor','none','EdgeColor',[0.333333 0 0.666667],...
'LineStyle','-', 'LineWidth',1);
xlabel('Data');
ylabel('Density')
LegHandles(end+1) = hLine;
LegText{end+1} = 'Outlays data';

% Create grid where function will be computed


XLim = get(gca,'XLim');
XLim = XLim + [-1 1] * 0.01 * diff(XLim);
XGrid = linspace(XLim(1),XLim(2),100);

% --- Create fit "fit 1"

% Fit this distribution to get parameter values


% To use parameter estimates from the original fit:
% pd1 = ProbDistUnivParam('normal',[ 20.70789473684, 5.434010505643])
pd1 = fitdist(Outlays, 'normal');
YPlot = pdf(pd1,XGrid);
hLine = plot(XGrid,YPlot,'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
LegHandles(end+1) = hLine;
LegText{end+1} = 'fit 1';

% Adjust figure
box on;
hold off;

% Create legend from accumulated handles and labels


hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'Location',
'NorthEast');
set(hLegend,'Interpreter','none');

14
function pd1 = createFit(Outlays)
%CREATEFIT Create plot of datasets and fits
% PD1 = CREATEFIT(OUTLAYS)
% Creates a plot, similar to the plot in the main distribution fitting
% window, using the data that you provide as input. You can
% apply this function to the same data you used with dfittool
% or with different data. You may want to edit the function to
% customize the code and this help message.
%
% Number of datasets: 1
% Number of fits: 1
%
% See also FITDIST.

% This function was automatically generated on 05-Nov-2017 20:47:12

% Output fitted probablility distribution: PD1

% Data from dataset "Outlays data":


% Y = Outlays

% Force all inputs to be column vectors


Outlays = Outlays(:);

% Prepare figure
clf;
hold on;
LegHandles = []; LegText = {};

% --- Plot data originally in dataset "Outlays data"


[CdfY,CdfX] = ecdf(Outlays,'Function','cdf'); % compute empirical function

15
hLine = stairs(CdfX,CdfY,'Color',[0.333333 0 0.666667],'LineStyle','-',
'LineWidth',1);
xlabel('Data');
ylabel('Cumulative probability')
LegHandles(end+1) = hLine;
LegText{end+1} = 'Outlays data';

% Create grid where function will be computed


XLim = get(gca,'XLim');
XLim = XLim + [-1 1] * 0.01 * diff(XLim);
XGrid = linspace(XLim(1),XLim(2),100);

% --- Create fit "fit 1"

% Fit this distribution to get parameter values


% To use parameter estimates from the original fit:
% pd1 = ProbDistUnivParam('normal',[ 20.70789473684, 5.434010505643])
pd1 = fitdist(Outlays, 'normal');
YPlot = cdf(pd1,XGrid);
hLine = plot(XGrid,YPlot,'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
LegHandles(end+1) = hLine;
LegText{end+1} = 'fit 1';

% Adjust figure
box on;
hold off;

% Create legend from accumulated handles and labels


hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'Location',
'NorthEast');
set(hLegend,'Interpreter','none');

Comment :
Distribution: Normal
Log likelihood: -235.983
Domain: -Inf < y < Inf
Mean: 20.7079
Variance: 29.5285

Parameter Estimate Std. Err.


mu 20.7079 0.623324
sigma 5.43401 0.445171

Estimated covariance of parameter estimates:


mu sigma
mu 0.388533 1.16959e-16
sigma 1.16959e-16 0.198178

2. Dfittool Receipts

16
17
function pd1 = createFit(Receipts)
%CREATEFIT Create plot of datasets and fits
% PD1 = CREATEFIT(RECEIPTS)
% Creates a plot, similar to the plot in the main distribution fitting
% window, using the data that you provide as input. You can
% apply this function to the same data you used with dfittool
% or with different data. You may want to edit the function to
% customize the code and this help message.
%
% Number of datasets: 1
% Number of fits: 1
%
% See also FITDIST.

% This function was automatically generated on 05-Nov-2017 21:21:23

% Output fitted probablility distribution: PD1

% Data from dataset "Receipts data":


% Y = Receipts

% Force all inputs to be column vectors


Receipts = Receipts(:);

% Prepare figure
clf;
hold on;
LegHandles = []; LegText = {};

% --- Plot data originally in dataset "Receipts data"

18
[CdfF,CdfX] = ecdf(Receipts,'Function','cdf'); % compute empirical cdf
BinInfo.rule = 1;
[~,BinEdge] = internal.stats.histbins(Receipts,[],[],BinInfo,CdfF,CdfX);
[BinHeight,BinCenter] = ecdfhist(CdfF,CdfX,'edges',BinEdge);
hLine = bar(BinCenter,BinHeight,'hist');
set(hLine,'FaceColor','none','EdgeColor',[0.333333 0 0.666667],...
'LineStyle','-', 'LineWidth',1);
xlabel('Data');
ylabel('Density')
LegHandles(end+1) = hLine;
LegText{end+1} = 'Receipts data';

% Create grid where function will be computed


XLim = get(gca,'XLim');
XLim = XLim + [-1 1] * 0.01 * diff(XLim);
XGrid = linspace(XLim(1),XLim(2),100);

% --- Create fit "fit 1"

% Fit this distribution to get parameter values


% To use parameter estimates from the original fit:
% pd1 = ProbDistUnivParam('normal',[ 17.42105263158, 2.351131120091])
pd1 = fitdist(Receipts, 'normal');
YPlot = pdf(pd1,XGrid);
hLine = plot(XGrid,YPlot,'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
LegHandles(end+1) = hLine;
LegText{end+1} = 'fit 1';

% Adjust figure
box on;
hold off;

% Create legend from accumulated handles and labels


hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'Location',
'NorthEast');
set(hLegend,'Interpreter','none');

19
20
function pd1 = createFit(Receipts)
%CREATEFIT Create plot of datasets and fits
% PD1 = CREATEFIT(RECEIPTS)
% Creates a plot, similar to the plot in the main distribution fitting
% window, using the data that you provide as input. You can
% apply this function to the same data you used with dfittool
% or with different data. You may want to edit the function to
% customize the code and this help message.
%
% Number of datasets: 1
% Number of fits: 1
%
% See also FITDIST.

% This function was automatically generated on 05-Nov-2017 22:03:52

% Output fitted probablility distribution: PD1

% Data from dataset "Receipts data":


% Y = Receipts

% Force all inputs to be column vectors


Receipts = Receipts(:);

% Prepare figure
clf;
hold on;
LegHandles = []; LegText = {};

% --- Plot data originally in dataset "Receipts data"

21
[CdfY,CdfX] = ecdf(Receipts,'Function','cdf'); % compute empirical
function
hLine = stairs(CdfX,CdfY,'Color',[0.333333 0 0.666667],'LineStyle','-',
'LineWidth',1);
xlabel('Data');
ylabel('Cumulative probability')
LegHandles(end+1) = hLine;
LegText{end+1} = 'Receipts data';

% Create grid where function will be computed


XLim = get(gca,'XLim');
XLim = XLim + [-1 1] * 0.01 * diff(XLim);
XGrid = linspace(XLim(1),XLim(2),100);

% --- Create fit "fit 1"

% Fit this distribution to get parameter values


% To use parameter estimates from the original fit:
% pd1 = ProbDistUnivParam('normal',[ 17.42105263158, 2.351131120091])
pd1 = fitdist(Receipts, 'normal');
YPlot = cdf(pd1,XGrid);
hLine = plot(XGrid,YPlot,'Color',[1 0 0],...
'LineStyle','-', 'LineWidth',2,...
'Marker','none', 'MarkerSize',6);
LegHandles(end+1) = hLine;
LegText{end+1} = 'fit 1';

% Adjust figure
box on;
hold off;

% Create legend from accumulated handles and labels


hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'Location',
'NorthEast');
set(hLegend,'Interpreter','none');

Distribution: Normal

Log likelihood: -172.311

Domain: -Inf < y < Inf

Mean: 17.4211

Variance: 5.52782

Parameter Estimate Std. Err.

mu 17.4211 0.269693

sigma 2.35113 0.192612

22
Estimated covariance of parameter estimates:

mu sigma

mu 0.0727344 -1.92503e-16

sigma -1.92503e-16 0.0370994

III.Distributions – How do I estimate the uncertainty of my

measures ?

1. median, mean, std, mode, skewness, kurtosis Outlays


>> median(Outlays)

ans =

20

>> mean(Outlays)

ans =

20.7079

>> std(Outlays)

ans =

5.43440

>> mode(Outlays)

ans =

18.8000

>> skewness(Outlays)

ans =

2.5078

>> kurtosis(Outlays)

ans =

12.1827

% skewness positif menunjukkan mean dan median di kanan modus dan jika dibuat
grafik akan cenderung ke kanan. Kurtosis yang lebih besar dari 3
(leptokurtik) menunjukkan distribusi dengan puncak relative tinggi.

23
2. median, mean, std, mode, skewness, kurtosis Receipts
>> median(Receipts)

ans =

17.7500

>> mean(Receipts)

ans =

17.4211

>> std(Receipts)

ans =

2.3511

>> mode(Receipts)

ans =

17.5000

>> skewness(Receipts)

ans =

-2.5823

>> kurtosis(Receipts)

ans =

11.4908

% skewness negatif menunjukkan mean di kiri modus, jika dibuat grafik maka
akan cenderung ke kiri. Kurtosis yang lebih besar dari 3 (leptokurtik)
menunjukkan distribusi dengan puncak relatif tinggi.

IV. The Linear Model – How can I create a simple model of my

data ?
%CREATEFIT1(RECEIPTS,OUTLAYS,SURPLUSORDEFICIT)
% Create a fit.

24
%
% Data for 'untitled fit 1' fit:
% X Input : Receipts
% Y Input : Outlays
% Z Output: SurplusorDeficit
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.

% Auto-generated by MATLAB on 05-Nov-2017 23:58:41

%% Fit: 'untitled fit 1'.


[xData, yData, zData] = prepareSurfaceData( Receipts, Outlays,
SurplusorDeficit );

% Set up fittype and options.


ft = 'linearinterp';
opts = fitoptions( ft );
opts.Normalize = 'on';

% Fit model to data.


[fitresult, gof] = fit( [xData, yData], zData, ft, opts );

% Plot fit with data.


figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'untitled fit 1', 'SurplusorDeficit vs. Receipts, Outlays',
'Location', 'NorthEast' );
% Label axes
xlabel( 'Receipts' );
ylabel( 'Outlays' );
zlabel( 'SurplusorDeficit' );
grid on
view( -97.5, 36.0 );

Hasil nya :

Linear interpolant:

f(x,y) = piecewise linear surface computed from p

where x is normalized by mean 17.42 and std 2.351

and where y is normalized by mean 20.71 and std 5.434

Coefficients:

p = coefficient structure

Goodness of fit:

25
SSE: 2.958e-31

R-square: 1

Adjusted R-square: NaN

RMSE: NaN

26
V. Machine Learning : Classification

>> figure,plot(Outlays,Receipts,'k*','MarkerSize',5)

>> US=[Outlays Receipts];

>> [i,centroid]=kmeans(US,2);

>> gscatter(Outlays,Receipts,kmeans(US,2))

>> hold on

>> plot(centroid(1,1),centroid(1,2),'bo','MarkerSize',12)

>> plot(centroid(2,1),centroid(2,2),'ro','MarkerSize',12)

>> disp('Jika data baru (11,9), maka masuk kelompok:')

>> disp(i(knnsearch(US,[11,9])))

>> disp('Jika data baru (45,50), maka masuk kelompok:')

>> disp(i(knnsearch(US,[45,50])))

Jika data baru (11, 9), maka masuk kelompok:

Jika data baru (45, 40), maka masuk kelompok:

27
VI. Machine Learning : Curve Fitting
%% DESCRIPTIVE TEXTImport data from spreadsheet
% Script for importing data from the following spreadsheet:
%
% Workbook: D:\02. S1 Industrial Engineering SGU\02. Engineering
% Statistic\MATLAB\Receipts and Outlays.xlsx Worksheet: Sheet1
%
% To extend the code for use with different selected data or a different
% spreadsheet, generate a function instead of a script.

% Auto-generated by MATLAB on 2017/11/02 20:55:17

%% Import the data


[~, ~, raw] = xlsread('D:\02. S1 Industrial Engineering SGU\02. Engineering
Statistic\MATLAB\Receipts and Outlays.xlsx','Sheet1','C5:F80');

%% Create output variable


data = reshape([raw{:}],size(raw));

%% Allocate imported array to column variable names


Year = data(:,1);
Outlays = data(:,2);
Receipts = data(:,3);
SurplusorDeficit = data(:,4);

%% Clear temporary variables


clearvars data raw;
%% NNSTART

% Solve an Input-Output Fitting problem with a Neural Network


% Script generated by NFTOOL
% Created Mon Nov 06 00:10:44 ICT 2017
%
% This script assumes these variables are defined:
%
% Receipts - input data.
% Outlays - target data.

inputs = Receipts';
targets = Outlays';

% Create a Fitting Network


hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize);

% Choose Input and Output Pre/Post-Processing Functions


% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};

% Setup Division of Data for Training, Validation, Testing


% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;

28
net.divideParam.testRatio = 15/100;

% For help on training function 'trainlm' type: help trainlm


% For a list of all training functions type: help nntrain
net.trainFcn = 'trainlm'; % Levenberg-Marquardt

% Choose a Performance Function


% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean squared error

% Choose Plot Functions


% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};

% Train the Network


[net,tr] = train(net,inputs,targets);

% Test the Network


outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)

% Recalculate Training, Validation and Test Performance


trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)

% View the Network


view(net)

% Plots
% Uncomment these lines to enable various plots.
figure, plotperform(tr)
figure, plottrainstate(tr)
figure, plotfit(net,inputs,targets)
figure, plotregression(targets,outputs)
figure, ploterrhist(errors)

performance =

14.1635

trainPerformance =

7.9688

valPerformance =

4.7740

testPerformance =

29
53.9636

30
31
32
33
34

You might also like