matlab用SVM对MNIST分类,图像处理基础数据库2的学习笔记——SVM、MATLAB、tensorflow分别训练和预测MNIST的数据集,基本,2SVMMATLABTensorflow,下,...

SVM

支持向量机

(Support Vector Machine, SVM)是一类按

监督学习

(supervised learning)方式对数据进行

二元分类

(binary classification)的广义线性分类器(generalized linear classifier),其

决策边界

是对学习样本求解的最大边距超平面(maximum-margin hyperplane)

**

流程

1. 收集数据:此处使用给定的文本文件

2. 准备数据:基于二值图像构造数据

3. 分析数据:对图像向量进行目测

4. 训练算法:采用三种不同的方法,不同的参数 线性分类器二次多项式核函数径向基核函数

5. 测试并计算错误率

以下直接使用sklearn.svm模块中的算法库对mnist数据集进行训练,并且进行预测:

import numpy as np

import struct

import matplotlib.pyplot as plt

import osimport pickle

##加载svm模型

from sklearn import svm

###用于做数据预处理

from sklearn import preprocessing

import time

##读取数据集

path='E:\\数据挖掘\\MNIST_data'

def load_mnist_train(path, kind='train'):

labels_path = os.path.join(path,'%s-labels.idx1-ubyte'% kind)

images_path = os.path.join(path,'%s-images.idx3-ubyte'% kind)

with open(labels_path, 'rb') as lbpath:

magic, n = struct.unpack('>II',lbpath.read(8))

labels = np.fromfile(lbpath,dtype=np.uint8)

with open(images_path, 'rb') as imgpath:

magic, num, rows, cols = struct.unpack('>IIII',imgpath.read(16))

images = np.fromfile(imgpath,dtype=np.uint8).reshape(len(labels), 784)

return images, labels

def load_mnist_test(path, kind='t10k'):

labels_path = os.path.join(path,'%s-labels.idx1-ubyte'% kind)

images_path = os.path.join(path,'%s-images.idx3-ubyte'% kind)

with open(labels_path, 'rb') as lbpath:

magic, n = struct.unpack('>II',lbpath.read(8))

labels = np.fromfile(lbpath,dtype=np.uint

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值