资源简介
《机器学习实战》Python3代码
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Tue Jul 3 12:06:45 2018
@author: Administrator
“““
from os import listdir
from numpy import *
from KNN_algr import *
def img2vec(filename):
‘‘‘this is to...将32X32的图像转化为1X1024的行向量‘‘‘
returnvec = zeros((11024))
with open(filename) as fp:
for i in range(32):
line = fp.readline()
for j in range(32):
returnvec[0 32*i + j] = int(line[j])
# returnVEC按32进位,j代表每位的32个元素
return returnvec
def HandWritingTest(train_dirtest_dir):
labels = []
File_list = listdir(train_dir)
# 将目录内的文件按名字放入列表,使用函数解析为数字
m = len(File_list)
train_mat = zeros((m1024))
for i in range(m):
fname = File_list[i]
fstr = fname.split(‘.‘)[0]
fnumber = int(fstr.split(‘_‘)[0])
# 比如‘digits/testDigits/0_13.txt‘,被拆分为013txt
# 此处0即为标签数字
labels.append(fnumber)
train_mat[i:] = img2vec(‘%s/%s‘ % (train_dirfname))
# labels is label_vec,同之前的KNN代码相同,存储标签
test_File_list = listdir(test_dir)
error = 0.0
test_m = len(test_File_list)
for i in range(test_m):
fname = test_File_list[i]
fstr = fname.split(‘.‘)[0]
fnumber = int(fstr.split(‘_‘)[0])
vec_test = img2vec(‘digits/testDigits/%s‘ % fname)
Result = classify_KNN(vec_test train_mat labels 3)
print(“the classifier came with: %d the real answer is :%d “ \
% (Result fnumber))
if(Result != fnumber) : error += 1
# 这部分和Test模块相同,直接copy过来就好
print(“the accuracy is %f | the error_rate is %f “ % \
(1- (float(error) /float(test_m))(float(error) /float(test_m))))
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\
文件 66 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\.gitattributes
文件 2881 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\README.md
目录 0 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\
文件 1867 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\Digit_recog.py
文件 634 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\Feature_scaling.py
文件 1075 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\KNN_algr.py
文件 989 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\Parse_data.py
文件 1468 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\TestData.py
文件 1 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\__init__.py
文件 873 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\__main__.py
文件 26067 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\datingTestSet2.txt
目录 0 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\
目录 0 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_0.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_1.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_10.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_11.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_12.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_13.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_14.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_15.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_16.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_17.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_18.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_19.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_2.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_20.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_21.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_22.txt
文件 1056 2018-08-19 03:49 Machine-Learning-in-Action-Python3-master\ch01-KNN\digits\testDigits\0_23.txt
............此处省略5878个文件信息
- 上一篇:段力辉大神翻译原版OpenCV-Python
- 下一篇:Python and xm
l
相关资源
- Python3学习笔记
- Python3.7.2中文文档-标准库-通用操作系
- Python3.7.2中文文档-标准库-Python数据类
- Long Short Terms Memory Networks with Python J
- python3基础教程第三版高清
- 随机森林python3实现代码(带数据集)
- dlib-19.18.0-cp37-cp37m-linux_armv7l.whl
- python3学习路线+思维导图
- Learn python3 the hard way
-
Python第三方库lxm
l最新3.7版本64位系 - 笨办法学python 3 第四版 英文
- python3爬虫
- python 实现KML转换为Excel的工具
- Beginning Python: From Novice to Professional
- Python3实现KNN的三个包含数据集,水果
- python3中文帮助手册和英文帮助手册
- 基于协同过滤的电影推荐系统 python
- 廖雪峰Python3完整版PDF
- dlib-19.8.1-cp36-cp36m-win_amd64.whl 支持w
- 跟老齐学python3.zip
- python机器学习5个数据科学家案例解析
- pygame-1.9.6-cp37-cp37m-win_amd64.zip
- pycharm pymssql python3.6
- django简易学生成绩管理
- ml-agents-master
- python3.7离线帮助文档英文原版
- 《Python 3.6 入门指南》中文版
- python3.6 API
- Learn Python3 The Hard Way(英文版PDF)(无
- pyltp wheel python3.5 3.6
评论
共有 条评论