SlideShare una empresa de Scribd logo
1 de 1
Descargar para leer sin conexión
Write a Matlab script for the function below, that runs the script 5 times and plots a bar graph
and error bar for the average accuracy. Here is the function:
function perceptron_classifier()
% load data data = load('bill_authentication.txt');
% split data into features and labels
X = data(:,1:4); y = data(:,5);
% normalize features
X = normalize(X);
% split data into training and testing sets
[X_train, y_train, X_test, y_test] = split_data(X, y, 0.8);
% train the perceptron classifier
mdl = fitcsvm(X_train, y_train, 'KernelFunction', 'linear', 'Standardize', true);
% predict on the test set
y_pred = predict(mdl, X_test);
% evaluate the model
accuracy = sum(y_pred == y_test)/length(y_test);
fprintf('Accuracy: %.2f%%n', accuracy*100);
end
function [X_train, y_train, X_test, y_test] = split_data(X, y, train_ratio)
% randomly shuffle data idx = randperm(size(X,1)); X = X(idx,:);
y = y(idx);
% split data into training and testing sets
split_idx = floor(size(X,1)*train_ratio);
X_train = X(1:split_idx,:);
y_train = y(1:split_idx);
X_test = X(split_idx+1:end,:);
y_test = y(split_idx+1:end);
end

Más contenido relacionado

Similar a Write a Matlab script for the function below, that runs the script 5.pdf

Ai_Project_report
Ai_Project_reportAi_Project_report
Ai_Project_report
Ravi Gupta
 
isabelle_webinar_jan..
isabelle_webinar_jan..isabelle_webinar_jan..
isabelle_webinar_jan..
butest
 

Similar a Write a Matlab script for the function below, that runs the script 5.pdf (20)

Assignment 6.1.pdf
Assignment 6.1.pdfAssignment 6.1.pdf
Assignment 6.1.pdf
 
Data mining with caret package
Data mining with caret packageData mining with caret package
Data mining with caret package
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)
 
Lab 2: Classification and Regression Prediction Models, training and testing ...
Lab 2: Classification and Regression Prediction Models, training and testing ...Lab 2: Classification and Regression Prediction Models, training and testing ...
Lab 2: Classification and Regression Prediction Models, training and testing ...
 
BPstudy sklearn 20180925
BPstudy sklearn 20180925BPstudy sklearn 20180925
BPstudy sklearn 20180925
 
Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62
 
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
Mini-lab 1: Stochastic Gradient Descent classifier, Optimizing Logistic Regre...
 
Ai_Project_report
Ai_Project_reportAi_Project_report
Ai_Project_report
 
6
66
6
 
Exam Prediction Machine Learning Algorithm
Exam Prediction Machine Learning Algorithm Exam Prediction Machine Learning Algorithm
Exam Prediction Machine Learning Algorithm
 
isabelle_webinar_jan..
isabelle_webinar_jan..isabelle_webinar_jan..
isabelle_webinar_jan..
 
Naïve Bayes.pptx
Naïve Bayes.pptxNaïve Bayes.pptx
Naïve Bayes.pptx
 
The Basics of MATLAB
The Basics of MATLABThe Basics of MATLAB
The Basics of MATLAB
 
Csci101 lect08b matlab_programs
Csci101 lect08b matlab_programsCsci101 lect08b matlab_programs
Csci101 lect08b matlab_programs
 
Xgboost
XgboostXgboost
Xgboost
 
Testing in those hard to reach places
Testing in those hard to reach placesTesting in those hard to reach places
Testing in those hard to reach places
 
Workshop - Introduction to Machine Learning with R
Workshop - Introduction to Machine Learning with RWorkshop - Introduction to Machine Learning with R
Workshop - Introduction to Machine Learning with R
 
Ml2 train test-splits_validation_linear_regression
Ml2 train test-splits_validation_linear_regressionMl2 train test-splits_validation_linear_regression
Ml2 train test-splits_validation_linear_regression
 
Training course lect2
Training course lect2Training course lect2
Training course lect2
 
CSL0777-L07.pptx
CSL0777-L07.pptxCSL0777-L07.pptx
CSL0777-L07.pptx
 

Más de krishahuja1992

Más de krishahuja1992 (20)

Write a small paraghraphFollow on to the Motion Envision an ecolo.pdf
Write a small paraghraphFollow on to the Motion Envision an ecolo.pdfWrite a small paraghraphFollow on to the Motion Envision an ecolo.pdf
Write a small paraghraphFollow on to the Motion Envision an ecolo.pdf
 
Write a program to create a binary tree andDisplay Write a program.pdf
Write a program to create a binary tree andDisplay Write a program.pdfWrite a program to create a binary tree andDisplay Write a program.pdf
Write a program to create a binary tree andDisplay Write a program.pdf
 
Write as much as you can please in the Mauritian Context. Will give .pdf
Write as much as you can please in the Mauritian Context. Will give .pdfWrite as much as you can please in the Mauritian Context. Will give .pdf
Write as much as you can please in the Mauritian Context. Will give .pdf
 
write a PseudocodeCreate a class called Sentence that contains the.pdf
write a PseudocodeCreate a class called Sentence that contains the.pdfwrite a PseudocodeCreate a class called Sentence that contains the.pdf
write a PseudocodeCreate a class called Sentence that contains the.pdf
 
Write a Python code to get a digital image and reduces its noise in .pdf
Write a Python code to get a digital image and reduces its noise in .pdfWrite a Python code to get a digital image and reduces its noise in .pdf
Write a Python code to get a digital image and reduces its noise in .pdf
 
Write a program in Java that displays a GUI fast food menu with chec.pdf
Write a program in Java that displays a GUI fast food menu with chec.pdfWrite a program in Java that displays a GUI fast food menu with chec.pdf
Write a program in Java that displays a GUI fast food menu with chec.pdf
 
Why my ocr is not performing for multi page pdf in javaimport java.pdf
Why my ocr is not performing for multi page pdf in javaimport java.pdfWhy my ocr is not performing for multi page pdf in javaimport java.pdf
Why my ocr is not performing for multi page pdf in javaimport java.pdf
 
Why was the bank seized by federal regulatorsWhich of the thr.pdf
Why was the bank seized by federal regulatorsWhich of the thr.pdfWhy was the bank seized by federal regulatorsWhich of the thr.pdf
Why was the bank seized by federal regulatorsWhich of the thr.pdf
 
Why is it important for real estate developers to work with various .pdf
Why is it important for real estate developers to work with various .pdfWhy is it important for real estate developers to work with various .pdf
Why is it important for real estate developers to work with various .pdf
 
Which statement is NOT trueFailing to reject the null hypothesis .pdf
Which statement is NOT trueFailing to reject the null hypothesis .pdfWhich statement is NOT trueFailing to reject the null hypothesis .pdf
Which statement is NOT trueFailing to reject the null hypothesis .pdf
 
will upvote if answer is good 5) Simplify the following Boolean func.pdf
will upvote if answer is good 5) Simplify the following Boolean func.pdfwill upvote if answer is good 5) Simplify the following Boolean func.pdf
will upvote if answer is good 5) Simplify the following Boolean func.pdf
 
Whichofthe folowing si NOT aprinciple of basic financial managemen.pdf
Whichofthe folowing si NOT aprinciple of basic financial managemen.pdfWhichofthe folowing si NOT aprinciple of basic financial managemen.pdf
Whichofthe folowing si NOT aprinciple of basic financial managemen.pdf
 
Willa, reci�n graduada de la universidad con poca experiencia relaci.pdf
Willa, reci�n graduada de la universidad con poca experiencia relaci.pdfWilla, reci�n graduada de la universidad con poca experiencia relaci.pdf
Willa, reci�n graduada de la universidad con poca experiencia relaci.pdf
 
Write a 12 page essay that explains why import and export documents.pdf
Write a 12 page essay that explains why import and export documents.pdfWrite a 12 page essay that explains why import and export documents.pdf
Write a 12 page essay that explains why import and export documents.pdf
 
Why the system says cannot find symbol of Calendar though I said imp.pdf
Why the system says cannot find symbol of Calendar though I said imp.pdfWhy the system says cannot find symbol of Calendar though I said imp.pdf
Why the system says cannot find symbol of Calendar though I said imp.pdf
 
Why do some populations growWhat factors help to determine the ra.pdf
Why do some populations growWhat factors help to determine the ra.pdfWhy do some populations growWhat factors help to determine the ra.pdf
Why do some populations growWhat factors help to determine the ra.pdf
 
Why are intravenous (IV) drug users at greater risk for skin abscess.pdf
Why are intravenous (IV) drug users at greater risk for skin abscess.pdfWhy are intravenous (IV) drug users at greater risk for skin abscess.pdf
Why are intravenous (IV) drug users at greater risk for skin abscess.pdf
 
Which statement about Hadoop is correcta) b) c).pdf
Which statement about Hadoop is correcta) b) c).pdfWhich statement about Hadoop is correcta) b) c).pdf
Which statement about Hadoop is correcta) b) c).pdf
 
With statistics, we have the data but we do not know the conditions..pdf
With statistics, we have the data but we do not know the conditions..pdfWith statistics, we have the data but we do not know the conditions..pdf
With statistics, we have the data but we do not know the conditions..pdf
 
You noted that organic foods are healthier and I found one study tha.pdf
You noted that organic foods are healthier and I found one study tha.pdfYou noted that organic foods are healthier and I found one study tha.pdf
You noted that organic foods are healthier and I found one study tha.pdf
 

Último

Último (20)

Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 

Write a Matlab script for the function below, that runs the script 5.pdf

  • 1. Write a Matlab script for the function below, that runs the script 5 times and plots a bar graph and error bar for the average accuracy. Here is the function: function perceptron_classifier() % load data data = load('bill_authentication.txt'); % split data into features and labels X = data(:,1:4); y = data(:,5); % normalize features X = normalize(X); % split data into training and testing sets [X_train, y_train, X_test, y_test] = split_data(X, y, 0.8); % train the perceptron classifier mdl = fitcsvm(X_train, y_train, 'KernelFunction', 'linear', 'Standardize', true); % predict on the test set y_pred = predict(mdl, X_test); % evaluate the model accuracy = sum(y_pred == y_test)/length(y_test); fprintf('Accuracy: %.2f%%n', accuracy*100); end function [X_train, y_train, X_test, y_test] = split_data(X, y, train_ratio) % randomly shuffle data idx = randperm(size(X,1)); X = X(idx,:); y = y(idx); % split data into training and testing sets split_idx = floor(size(X,1)*train_ratio); X_train = X(1:split_idx,:); y_train = y(1:split_idx); X_test = X(split_idx+1:end,:); y_test = y(split_idx+1:end); end