Importing Data
Instructions are in the task pane to the left. Complete and submit each task one at a time.
Task 1
letter = readtable("J.txt");
Task 2
plot(letter.X,letter.Y)
Task 3
axis equal
Task 4
letter = readtable("M.txt");
plot(letter.X,letter.Y)
axis equal
Preprocessing Data
Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code loads the data.
letter = readtable("M.txt")
Task 1
letter.X = 1.5*letter.X;
View the result
plot(letter.X,letter.Y)
axis equal
Task 2
letter.Time = letter.Time - letter.Time(1)
letter.Time = letter.Time/1000
View the result
plot(letter.Time,letter.X)
plot(letter.Time,letter.Y)
Calculate Features
Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code loads and preprocesses the data.
letter = readtable("M.txt");
letter.X = letter.X*1.5;
letter.Time = (letter.Time - letter.Time(1))/1000
plot(letter.X,letter.Y)
axis equal
Task 1
dur = letter.Time(end)
Task 2
aratio = range(letter.Y)/range(letter.X)
View Features
Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code loads the data.
load featuredata.mat
features
Task 1
scatter(features.AspectRatio,features.Duration)
Task 2
gscatter(features.AspectRatio,features.Duration,features.Character)
Fit a Model
Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code loads the data.
load featuredata.mat
features
testdata
Task 1
knnmodel = fitcknn(features,"Character")
Task 2
predictions = predict(knnmodel,testdata)
Task 3
knnmodel = fitcknn(features,"Character","NumNeighbors",5)
predictions = predict(knnmodel,testdata)
Further Practice
[predictions,testdata.Character]
Evaluate the Model
Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code loads the data.
load featuredata.mat
testdata
knnmodel = fitcknn(features,"Character","NumNeighbors",5);
predictions = predict(knnmodel,testdata)
Task 1
iscorrect = predictions == testdata.Character
Task 2
accuracy = sum(iscorrect)/numel(predictions)
Task 3
iswrong = predictions ~= testdata.Character
misclassrate = sum(iswrong)/numel(predictions)
Task 4
confusionchart(testdata.Character,predictions);
Apply Model to Many Letters
Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code loads the data.
load featuredata13letters.mat
features
testdata
Task 1
gscatter(features.AspectRatio,features.Duration,features.Character)
xlim([0 10])
Task 2
knnmodel = fitcknn(features,"Character","NumNeighbors",5)
predictions=predict(knnmodel,testdata)
Task 3
iswrong=predictions~=testdata.Character
misclass=sum(iswrong)/numel(predictions)
confusionchart(testdata.Character,predictions)