Maltab-机器学习-Classification Workflow

本文提供了一套完整的手写字符识别教程,从数据导入、预处理到特征计算,再到模型训练与评估,最后将模型应用于多个字母的识别任务。通过一系列步骤,包括读取表格数据、绘制坐标轴相等的图表、调整数据比例、计算特征、使用KNN模型进行预测,以及评估模型准确性,读者可以学习如何建立和优化手写字符识别系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南叔先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值