• 西一路
    了解作者
  • Python
    开发工具
  • 14KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 2
    下载次数
  • 2020-03-03 12:25
    上传日期
支持向量机实现多分类,解决多分类的问题,模式识别等
多分类python代码.zip
  • 多分类python代码.doc
    46KB
内容介绍
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <meta name="generator" content="pdf2htmlEX"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <link rel="stylesheet" href="https://static.pudn.com/base/css/base.min.css"> <link rel="stylesheet" href="https://static.pudn.com/base/css/fancy.min.css"> <link rel="stylesheet" href="https://static.pudn.com/prod/directory_preview_static/626ba4ff7ae5df2aa7188bdf/raw.css"> <script src="https://static.pudn.com/base/js/compatibility.min.js"></script> <script src="https://static.pudn.com/base/js/pdf2htmlEX.min.js"></script> <script> try{ pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({}); }catch(e){} </script> <title></title> </head> <body> <div id="sidebar" style="display: none"> <div id="outline"> </div> </div> <div id="pf1" class="pf w0 h0" data-page-no="1"><div class="pc pc1 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/626ba4ff7ae5df2aa7188bdf/bg1.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x1 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">libSVM.py </div><div class="t m0 x1 h4 y3 ff2 fs0 fc0 sc0 ls0 ws0">&#35813;&#25991;&#20214;&#23454;&#29616;&#20102;&#19968;&#20010;<span class="_ _0"> </span><span class="ff3">SVM<span class="_ _0"> </span></span>&#22810;&#20998;&#31867;&#22120;<span class="ff3">,</span>&#20854;&#23454;&#29616;&#21407;&#29702;&#26159;&#65306;</div><div class="t m0 x1 h4 y4 ff2 fs0 fc0 sc0 ls0 ws0">&#23545;<span class="_ _1"></span>&#20110;<span class="_ _1"></span>&#26679;<span class="_ _1"></span>&#26412;<span class="_ _1"></span>&#20013;<span class="_ _1"></span>&#30340;<span class="_ _1"></span>&#27599;<span class="_ _1"></span>&#20004;<span class="_ _1"></span>&#20010;<span class="_ _1"></span>&#31867;<span class="_ _1"></span>&#21035;<span class="_ _1"></span>&#20043;<span class="_ _1"></span>&#38388;<span class="_ _1"></span>&#37117;<span class="_ _1"></span>&#35757;<span class="_ _1"></span>&#32451;<span class="_ _1"></span>&#19968;<span class="_ _1"></span>&#20010;<span class="_ _2"> </span><span class="ff3">SVM<span class="_ _3"> </span></span>&#20108;<span class="_ _1"></span>&#20998;<span class="_ _1"></span>&#31867;<span class="_ _1"></span>&#22120;<span class="_ _1"></span>&#12290;<span class="_ _1"></span>&#23545;<span class="_ _1"></span>&#20110;<span class="_ _4"> </span><span class="ff3">k<span class="_ _3"> </span></span>&#20010;<span class="_ _1"></span>&#31867;<span class="_ _1"></span>&#21035;<span class="_ _1"></span>&#65292;<span class="_ _1"></span><span class="ff3"> <span class="_ _1"></span></span>&#20849;</div><div class="t m0 x1 h4 y5 ff2 fs0 fc0 sc0 ls0 ws0">&#21487;<span class="_ _5"></span>&#35757;<span class="_ _5"></span>&#32451;<span class="_ _5"></span>&#20986;<span class="_ _4"> </span><span class="ff3">k(k-1)/2<span class="_"> </span></span>&#20010;<span class="_ _4"> </span><span class="ff3">SVM<span class="_ _2"> </span></span>&#20108;<span class="_ _1"></span>&#20998;<span class="_ _5"></span>&#31867;<span class="_ _5"></span>&#22120;<span class="_ _5"></span>&#12290;<span class="_ _5"></span>&#22312;<span class="_ _5"></span>&#39044;<span class="_ _1"></span>&#27979;<span class="_ _5"></span>&#26102;<span class="_ _5"></span>&#65292;<span class="_ _5"></span>&#23558;<span class="_ _5"></span>&#27979;<span class="_ _5"></span>&#35797;<span class="_ _5"></span>&#26679;<span class="_ _5"></span>&#20363;<span class="_ _1"></span>&#20998;<span class="_ _5"></span>&#21035;<span class="_ _5"></span>&#36755;<span class="_ _5"></span>&#20837;<span class="_ _5"></span>&#21040;<span class="_ _2"> </span><span class="ff3">k(k-</span></div><div class="t m0 x1 h4 y6 ff3 fs0 fc0 sc0 ls0 ws0">1)/2<span class="_ _0"> </span><span class="ff2">&#20998;&#31867;&#22120;&#20013;&#12290;</span></div><div class="t m0 x1 h4 y7 ff2 fs0 fc0 sc0 ls0 ws0">&#20551;&#35774;&#65288;<span class="ff3">i,j)</span>&#34920;&#31034;&#21010;&#20998;&#31867;&#21035;<span class="_ _0"> </span><span class="ff3">i<span class="_ _0"> </span></span>&#21644;&#31867;&#21035;<span class="_ _0"> </span><span class="ff3">j<span class="_ _0"> </span></span>&#30340;<span class="_ _0"> </span><span class="ff3">SVM<span class="_ _0"> </span></span>&#20998;&#31867;&#22120;</div><div class="t m0 x1 h4 y8 ff2 fs0 fc0 sc0 ls0 ws0">&#23545;&#20110;&#27599;&#20010;&#20998;&#31867;&#22120;<span class="ff3">(i,j)</span>&#65306;</div><div class="t m0 x1 h4 y9 ff2 fs0 fc0 sc0 ls0 ws0">&#33509;&#20998;&#31867;&#32467;&#26524;&#20026;<span class="ff3">+1</span>&#65292;&#21017;<span class="_ _0"> </span><span class="ff3">count[i] +=1</span></div><div class="t m0 x1 h4 ya ff2 fs0 fc0 sc0 ls0 ws0">&#33509;&#20998;&#31867;&#32467;&#26524;&#20026;<span class="ff3">-1</span>&#65292;&#21017;<span class="_ _0"> </span><span class="ff3">count[j] +=1</span></div><div class="t m0 x1 h4 yb ff2 fs0 fc0 sc0 ls0 ws0">&#26368;&#21518;&#20998;&#31867;&#32467;&#26524;&#21462;&#30456;&#24212;&#31867;&#21035;&#35745;&#25968;&#26368;&#22823;&#30340;&#37027;&#20010;&#31867;&#21035;&#20316;&#20026;&#26368;&#32456;&#20998;&#31867;&#32467;&#26524;</div><div class="t m0 x1 h4 yc ff2 fs0 fc0 sc0 ls0 ws0">&#26412;&#25991;<span class="_ _1"></span>&#20214;<span class="_ _1"></span>&#36824;&#23454;<span class="_ _1"></span>&#29616;<span class="_ _1"></span>&#20102;&#23558;<span class="_ _1"></span>&#35757;<span class="_ _1"></span>&#32451;&#30340;<span class="_ _1"></span>&#27169;<span class="_ _1"></span>&#22411;&#20445;<span class="_ _1"></span>&#23384;<span class="_ _1"></span>&#25104;&#25991;<span class="_ _1"></span>&#20214;<span class="_ _1"></span>&#65292;&#26041;<span class="_ _1"></span>&#20415;<span class="_ _1"></span>&#39044;&#27979;<span class="_ _1"></span>&#26102;<span class="_ _1"></span>&#30452;&#25509;<span class="_ _1"></span>&#20174;<span class="_ _1"></span>&#25991;&#20214;<span class="_ _1"></span>&#35835;<span class="_ _1"></span>&#21462;&#65292;<span class="_ _1"></span>&#30465;<span class="_ _1"></span>&#21435;</div><div class="t m0 x1 h4 yd ff2 fs0 fc0 sc0 ls0 ws0">&#20102;&#20877;&#27425;&#35757;&#32451;&#30340;&#26102;&#38388;&#12290;</div><div class="t m0 x1 h4 ye ff1 fs0 fc1 sc0 ls0 ws0">** <span class="ff2 sc1">&#20363;&#23376;</span></div><div class="t m0 x1 h5 yf ff3 fs0 fc1 sc0 ls0 ws0">def main():</div><div class="t m0 x1 h5 y10 ff3 fs0 fc1 sc0 ls0 ws0"> '''</div><div class="t m0 x1 h5 y11 ff3 fs0 fc1 sc0 ls0 ws0"> data,label = loadImage('trainingDigits')</div><div class="t m0 x1 h5 y12 ff3 fs0 fc1 sc0 ls0 ws0"> svm = LibSVM(data, label, 200, 0.0001, 10000, name='rbf', theta=20)</div><div class="t m0 x1 h5 y13 ff3 fs0 fc1 sc0 ls0 ws0"> svm.train()</div><div class="t m0 x1 h5 y14 ff3 fs0 fc1 sc0 ls0 ws0"> svm.save("svm.txt")</div><div class="t m0 x1 h5 y15 ff3 fs0 fc1 sc0 ls0 ws0"> '''</div><div class="t m0 x1 h5 y16 ff3 fs0 fc1 sc0 ls0 ws0"> svm = LibSVM.load("svm.txt")</div><div class="t m0 x1 h5 y17 ff3 fs0 fc1 sc0 ls0 ws0"> test,testlabel = loadImage('testDigits')</div><div class="t m0 x1 h5 y18 ff3 fs0 fc1 sc0 ls0 ws0"> svm.predict(test,testlabel)</div><div class="t m0 x1 h5 y19 ff3 fs0 fc0 sc0 ls0 ws0">import sys</div><div class="t m0 x1 h5 y1a ff3 fs0 fc0 sc0 ls0 ws0">from numpy import *</div><div class="t m0 x1 h5 y1b ff3 fs0 fc0 sc0 ls0 ws0">from svm import *</div><div class="t m0 x1 h5 y1c ff3 fs0 fc0 sc0 ls0 ws0">from os import listdir</div><div class="t m0 x1 h5 y1d ff3 fs0 fc0 sc0 ls0 ws0">from plattSMO import PlattSMO</div><div class="t m0 x1 h5 y1e ff3 fs0 fc0 sc0 ls0 ws0">import pickle</div><div class="t m0 x1 h5 y1f ff3 fs0 fc0 sc0 ls0 ws0">class LibSVM:</div><div class="t m0 x1 h5 y20 ff3 fs0 fc0 sc0 ls0 ws0"> def __init__(self,data=[],label=[],C=0,toler=0,maxIter=0,**kernelargs):</div><div class="t m0 x1 h6 y21 ff3 fs0 fc0 sc0 ls0 ws0"> <span class="_ _1"></span> <span class="_ _1"></span>self.classlabel = unique(label)<span class="_ _1"></span>#<span class="ff4 fc1"> <span class="ff2 fs1">&#23545;&#20110;&#19968;&#32500;&#25968;<span class="_ _1"></span>&#32452;&#25110;&#32773;&#21015;&#34920;&#65292;<span class="_ _5"></span><span class="ff4">unique<span class="_ _6"> </span></span>&#20989;&#25968;&#21435;&#38500;&#20854;&#20013;<span class="_ _1"></span>&#37325;&#22797;&#30340;&#20803;&#32032;&#65292;</span></span></div><div class="t m0 x1 h7 y22 ff2 fs1 fc1 sc0 ls0 ws0">&#24182;&#25353;&#20803;&#32032;&#30001;&#22823;&#21040;&#23567;&#36820;&#22238;&#19968;&#20010;&#26032;&#30340;&#26080;&#20803;&#32032;&#37325;&#22797;&#30340;&#20803;&#32452;&#25110;&#32773;&#21015;&#34920;</div><div class="t m0 x1 h5 y23 ff3 fs0 fc0 sc0 ls0 ws0"> self.class<span class="fc1">Num</span> = len(self.classlabel)</div><div class="t m0 x1 h5 y24 ff3 fs0 fc0 sc0 ls0 ws0"> self.class<span class="fc1">fyNum</span> = (self.classNum * (self.classNum-1))/2</div><div class="t m0 x1 h5 y25 ff3 fs0 fc0 sc0 ls0 ws0"> self.classfy = []</div><div class="t m0 x1 h5 y26 ff3 fs0 fc0 sc0 ls0 ws0"> self.dataSet={}</div><div class="t m0 x1 h5 y27 ff3 fs0 fc0 sc0 ls0 ws0"> self.kernelargs = kernelargs</div><div class="t m0 x1 h5 y28 ff3 fs0 fc0 sc0 ls0 ws0"> self.C = C</div></div></div><div class="pi" data-data='{"ctm":[1.611850,0.000000,0.000000,1.611850,0.000000,0.000000]}'></div></div> </body> </html>
评论
    相关推荐
    • keans分类模式识别
      对已有样本进行聚类,找到聚类中心 比较实用的模式识别算法
    • 模式识别朴素贝叶斯分类
      模式识别朴素贝叶斯分类器下载模式识别朴素贝叶斯分类器下载
    • 模式识别-数字分类识别程序
      关于模式识别课程的学习代码,采用c语言实现通过学习训练实现对手写数字的自动识别。
    • 模式识别_分类器设计
      很不错的c语言编写的k均值法,分类器设计,klT变换
    • 模式识别-分类
      通过设计线性分类器;最小风险贝叶斯分类器;监督学习法分层聚类分析;K-L变换提取有效特征,设计支持向量机对给定样本进行有效分类并分析结果。
    • 模式识别和模式分类答案
      包含模式识别课后题详解以及模式分类部分课后题答案。有助于初学者的学习
    • 模式识别实验贝叶斯分类
      模式识别的实验,贝叶斯分类器实现男生女生的分离,实现 了基本的分类器的功能
    • 模式识别作业-贝叶斯分类
      模式识别作业-贝叶斯分类器。贝叶斯分类器的分类原理是通过某对象的先验概率,利用贝叶斯公式计算出其后验概率,即该对象属于某一类的概率,选择具有最大后验概率的类作为该对象所属的类。也就是说,贝叶斯分类器是...
    • 模式识别分类方法
      采用分类器对数据进行有效分类,有具体的代码和实验结果。
    • 模式识别分类器设计
      模式识别贝叶斯、BP、决策树分类器比较。内含MTALAB代码、PPT、数据集