Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69d8cb9

Browse files
committed
knn_data_num
1 parent 7eb8da3 commit 69d8cb9

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

‎ch46-机器学习-K近邻/2-使用kNN对手写数字OCR.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
np.savez('knn_data.npz', train=train, train_labels=train_labels,test=test,test_labels=test_labels)
4949

5050
# Now load the data
51-
with np.load('knn_data.npz') as data:
51+
with np.load('knn_data_num.npz') as data:
5252
print(data.files)
5353
train = data['train']
5454
train_labels = data['train_labels']

‎ch46-机器学习-K近邻/2-英文字母的OCR.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Load the data, converters convert the letter to a number
1616
data = np.loadtxt('../data/letter-recognition.data', dtype='float32', delimiter=',',
17-
converters={0: lambda ch: ord(ch) - ord('A')})
17+
converters={0: lambda ch: ord(ch) - ord('A')})#20000个
1818
# split the data to two, 10000 each for train and test
1919
train, test = np.vsplit(data, 2)
2020
# split trainData and testData to features and responses
@@ -29,6 +29,13 @@
2929
correct = np.count_nonzero(result == labels)
3030
accuracy = correct * 100.0 / 10000
3131
print(accuracy)
32-
#准确率 到了 93.22%。同样你可以 增加 练样本的数 来提 准确 率
32+
#准确率 到了 93.22%。同样你可以 增加训练样本的数量来提 准确率
3333

34-
#TODO 怎样预测字母?
34+
with np.load('knn_data_alphabet.npz') as data:
35+
print(data.files)
36+
train = data['train']
37+
train_labels = data['train_labels']
38+
test = data['test']
39+
test_labels = data['test_labels']
40+
41+
#怎样预测字母?跟预测数字的一样
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2017年8月10日 17:59
3+
# @Author : play4fun
4+
# @File : 同时预测数字和英文字母1.py
5+
# @Software: PyCharm
6+
7+
"""
8+
同时预测数字和英文字母1.py:
9+
"""
10+

‎ch46-机器学习-K近邻/预测手写数字1.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import cv2
1313
from matplotlib import pyplot as plt
1414

15-
with np.load('knn_data.npz') as data:
15+
with np.load('knn_data_num.npz') as data:
1616
print(data.files)
1717
train = data['train']
1818
train_labels = data['train_labels']

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /