资源简介
支持向量机的几个Python代码例子,分别是有SMO实现,核函数的应用,以及手写数字识别的代码例子,下载即可运行

代码片段和文件信息
# -*- coding: cp936 -*-
‘‘‘
Created on Nov 4 2010
Chapter 5 source file for Machine Learing in Action
@author: Peter
‘‘‘
from numpy import *
from time import sleep
def loadDataSet(fileName):
dataMat = []; labelMat = []
fr = open(fileName)
for line in fr.readlines():
lineArr = line.strip().split(‘\t‘)
dataMat.append([float(lineArr[0]) float(lineArr[1])])
labelMat.append(float(lineArr[2]))
return dataMatlabelMat
def selectJrand(im):
j=i #we want to select any J not equal to i
while (j==i):
j = int(random.uniform(0m))
return j
def clipAlpha(ajHL):
if aj > H:
aj = H
if L > aj:
aj = L
return aj
class optStruct:
def __init__(selfdataMatIn classLabels C toler): # Initialize the structure with the parameters
self.X = dataMatIn
self.labelMat = classLabels
self.C = C
self.tol = toler
self.m = shape(dataMatIn)[0]
self.alphas = mat(zeros((self.m1)))
self.b = 0
self.eCache = mat(zeros((self.m2))) #first column is valid flag
def calcEk(oS k):
fXk = float(multiply(oS.alphasoS.labelMat).T*oS.X*oS.X[k:].T + oS.b)
Ek = fXk - float(oS.labelMat[k])
return Ek
def selectJ(i oS Ei): #this is the second choice -heurstic and calcs Ej
maxK = -1;
maxDeltaE = 0;
Ej = 0
oS.eCache[i] = [1Ei] #set valid #choose the alpha that gives the maximum delta E
validEcacheList = nonzero(oS.eCache[:0].A)[0]
if (len(validEcacheList)) > 1:
for k in validEcacheList: #loop through valid Ecache values and find the one that maximizes delta E
if k == i: continue #don‘t calc for i waste of time
Ek = calcEk(oS k)
deltaE = abs(Ei - Ek)
if (deltaE > maxDeltaE):
maxK = k;
maxDeltaE = deltaE;
Ej = Ek
return maxK Ej
else: #in this case (first time around) we don‘t have any valid eCache values
j = selectJrand(i oS.m)
Ej = calcEk(oS j)
return j Ej
def updateEk(oS k):#after any alpha has changed update the new value in the cache
Ek = calcEk(oS k)
oS.eCache[k] = [1Ek]
def innerL(i oS):
Ei = calcEk(oS i)
if ((oS.labelMat[i]*Ei < -oS.tol) and (oS.alphas[i] < oS.C)) or ((oS.labelMat[i]*Ei > oS.tol) and (oS.alphas[i] > 0)):
jEj = selectJ(i oS Ei) #this has been changed from selectJrand
alphaIold = oS.alphas[i].copy();
alphaJold = oS.alphas[j].copy();
if (oS.labelMat[i] != oS.labelMat[j]):
L = max(0 oS.alphas[j] - oS.alphas[i])
H = min(oS.C oS.C + oS.alphas[j] - oS.alphas[i])
else:
L = max(0 oS.alphas[j] + oS.alphas[i] - oS.C)
H = min(oS.C oS.alphas[j] + oS.alphas[i])
if L==H:
print “L==H“;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-12-17 10:21 支持向量机(ML in action)整理\
文件 5558 2014-12-16 22:38 支持向量机(ML in action)整理\optimalMethod.py
文件 3697 2014-12-16 21:11 支持向量机(ML in action)整理\simple.py
文件 7366 2014-12-17 09:44 支持向量机(ML in action)整理\svmRBF.py
文件 2208 2010-11-04 14:13 支持向量机(ML in action)整理\testSet.txt
文件 2945 2010-11-26 18:16 支持向量机(ML in action)整理\testSetRBF.txt
文件 2951 2010-11-26 18:17 支持向量机(ML in action)整理\testSetRBF2.txt
目录 0 2014-12-17 08:43 支持向量机(ML in action)整理\作图\
文件 2336 2010-11-03 16:30 支持向量机(ML in action)整理\作图\notLinSeperable.py
文件 835 2011-02-16 18:24 支持向量机(ML in action)整理\作图\plotRBF.py
文件 1452 2010-11-23 19:46 支持向量机(ML in action)整理\作图\plotSupportVectors.py
文件 2208 2010-11-04 14:13 支持向量机(ML in action)整理\作图\testSet.txt
文件 2950 2014-12-17 08:51 支持向量机(ML in action)整理\作图\testSetRBF2.txt
目录 0 2014-12-17 10:17 支持向量机(ML in action)整理\识别数字1和9\
文件 7617 2014-12-17 10:18 支持向量机(ML in action)整理\识别数字1和9\svmMLiA.py
目录 0 2014-12-16 22:40 支持向量机(ML in action)整理\识别数字1和9\testDigits\
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_0.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_1.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_10.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_11.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_12.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_13.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_14.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_15.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_16.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_17.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_18.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_19.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_2.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_20.txt
文件 1088 2010-10-07 05:35 支持向量机(ML in action)整理\识别数字1和9\testDigits\1_21.txt
............此处省略574个文件信息
相关资源
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
评论
共有 条评论