# Matlab Program to Create AI System Design Assignment Solution.

## Instructions

Objective
If you need expert assistance with your artificial intelligence assignment, our team is here to help! In line with your request, we can create a program to design an AI system using MATLAB. In this program, we will utilize MATLAB's powerful tools and libraries to implement various AI algorithms and techniques. The AI system will be capable of learning from data, making intelligent decisions, and adapting to new information.

## Requirements and Specifications

Homework Brief
2021-22

Module Title: Artificial Intelligence and MachineLearning Module Code: EL4011
Level: 7

Artificial

Intelligence

System

Design

Marking scheme

Your report should contain the following elements; it will be marked in accordance with the following marking scheme:

Item

Weight(%)

ArtificialIntelligence System Design

1. Description of the selected problem

10

2. Consideration of any ethical, safety and governanceissues

10

3. Description of the AI methodology for solving the presented problem

20

ActivityRecognition

4. Feature selection / dimensionality reduction /data outliers detection

10

5. Machine Learning algorithm selection and training.
;
20

6. Quantitative evaluation of the proposed solution.

20

7. Presentation of the report, including conclusions.

10

Total

100

References

MATLAB (2018b or later): Classification Learner App

Bishop, C. M. (2006) Pattern Recognition and Machine Learning. Springer Marshal, S. (2009) Machine Learning, an Algorithmic Perspective. CRC Press

Source Code

clc, clear all, close all

%% Loas Data

%% Feature selection

% For this, we use MATLAB's fscmrmr function which rates all the

% features in the dataset. The function returns the index of the

% features with their scores. The most important features are those

% with the highest scores

[idx, scores] = fscmrmr(Train_X, Train_Y);

% Sort scores in descending order

[scores, scores_idx] = sort(scores, 'descend');

% Normalize scores

scores = (scores - min(scores))/(max(scores)-min(scores));

% Pick the index of the scores

idx = idx(scores_idx);

figure

bar(idx,scores)

xlabel('Number of feature')

ylabel('Score')

accs = zeros(1, 60);

for i = 1:60

I = idx(1:i);

Train_XX = Train_X(:, I);

Test_XX = Test_X(:, I);

%% Convert dataset to tables

% Define var names

varnames = {};

for i = 1:size(Train_XX, 2)

varnames{i} = char(sprintf("Var%d", i));

end

varnames_test = varnames;

varnames{size(Train_XX, 2)+1} = char("Class");

%% Convert data from arrays to table

train = [array2table(Train_XX), table(Train_Y)];

train.Properties.VariableNames = varnames;

test = array2table(Test_XX);

test.Properties.VariableNames = varnames_test;

%% Create Model

% We will use a Decision Tree since this is a Classification Model

% tic

tree = fitctree(train, 'Class', 'SplitCriterion', 'gdi', 'MaxNumSplits', 60, 'Surrogate', 'off');

% toc

% Predict on Training & Test sets

Y_CT_train = predict(tree,train);

Y_CT_test = predict(tree,test);

% view(tree,'mode','graph')

% Calculate confusion matrices using prediction results

% C_CT_train = confusionmat(Train_Y,Y_CT_train);

% Measure training accuracy

acc = sum(Y_CT_train == Train_Y)/length(Y_CT_train);

fprintf("The training accuracy of the model for %d features is %.2f%%\n", i, acc*100);

accs(i) = acc;

end

% Get the optimal number of features and the maximum accuracy

[max_acc, loc] = max(accs);

fprintf("The maximum accuracy was %.2f%% and was obtained when using the first %d most important features\n", max_acc, loc);

figure

plot(accs), grid on

xlabel('Number of features used')

ylabel('Accuracy')