91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 245KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-05-15
  • 語言: Python
  • 標簽: LSSVM??python??

資源簡介

LSSVM實例代碼,

資源截圖

代碼片段和文件信息

#?-*-?coding:?utf-8?-*-
“““
Created?on?Wed?May?16?12:48:56?2018

@author:?lj
“““

from?numpy?import?*

def?loadDataSet(filename):
????‘‘‘導入數(shù)據(jù)
????input:?filename:文件名
output:dataMat(list)樣本特征
???????labelMat(list)樣本標簽
????‘‘‘
????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?kernelTrans(XAkTup):
????‘‘‘數(shù)據(jù)集中每一個數(shù)據(jù)向量與數(shù)據(jù)A的核函數(shù)值
????input:?X--特征數(shù)據(jù)集
???????????A--輸入向量
???????????kTup--核函數(shù)參量定義
????output:?K--數(shù)據(jù)集中每一個數(shù)據(jù)向量與A的核函數(shù)值組成的矩陣
????‘‘‘
????X?=?mat(X)
????mn?=?shape(X)
????K?=?mat(zeros((m1)))
????if?kTup[0]?==?‘lin‘:
????????K?=?X?*?A.T
????elif?kTup[0]?==?‘rbf‘:
????????for?j?in?range(m):
????????????deltaRow?=?X[j:]?-?A
????????????K[j]?=?deltaRow?*?deltaRow.T
????????K?=?exp(K/(-1?*?kTup[1]?**?2))
????else:?raise?NameError(‘Houston?We?Have?a?Problem?--?That?Kernel?is?not?recognized‘)
????return?K
????
class?optStruct:
????def?__init__(selfdataMatInclassLabelsCkTup):
????????self.X?=?dataMatIn
????????self.labelMat?=?classLabels
????????self.C?=?C
????????self.m?=?shape(dataMatIn)[0]
????????self.alphas?=?mat(zeros((self.m1)))
????????self.b?=?0
????????self.K?=?mat(zeros((self.mself.m)))??#特征數(shù)據(jù)集合中向量兩兩核函數(shù)值組成的矩陣,[ij]表示第i個向量與第j個向量的核函數(shù)值
????????for?i?in?range(self.m):
????????????self.K[:i]?=?kernelTrans(self.X?self.X[i:]?kTup)
????????????

def?leastSquares(dataMatInclassLabelsCkTup):
????‘‘‘最小二乘法求解alpha序列
????input:dataMatIn(list):特征數(shù)據(jù)集
??????????classLabels(list):分類標簽集
??????????C(float):參數(shù),(松弛變量,允許有些數(shù)據(jù)點可以處于分隔面的錯誤一側(cè))
??????????kTup(string):?核函數(shù)類型和參數(shù)選擇?
????output:b(float):w.T*x+b=y中的b
???????????alphas(mat):alphas序列??????
????‘‘‘
????print(“mat(dataMatIn):\n“mat(dataMatIn))
????print(“mat(dataMatIn).shape:“mat(dataMatIn).shape)?#?100?*?2
????print(“mat(classLabels):\n“mat(classLabels))
????print(“mat(classLabels).shape:“mat(classLabels).shape)?#?1?*?100
????print(“mat(classLabels).transpose():\n“mat(classLabels).transpose())?#?轉(zhuǎn)置?100?*?1
????print(“C:“C)?#?0.6
????print(“kTup:“kTup)?#?(‘rbf‘0.3)
????#?調(diào)用?optStruct?方法,得到自定義的變量
????oS?=?optStruct(mat(dataMatIn)mat(classLabels).transpose()CkTup)
????print(“oS.X:\n“oS.X)?#?100?*?2
????print(“oS.labelMat:\n“oS.labelMat)?#?100?*?1
????print(“oS.C:\n“oS.C)
????print(“oS.m:\n“oS.m)
????print(“alphas:\n“oS.alphas)
????print(“oS.b:\n“oS.b)?#?0
????print(“oS.K:\n“oS.K)?#
????print(“oS.K.shape:\n“oS.K.shape)?#?100?*?100
????#?打印自定義變量得到的參數(shù)
????##1.參數(shù)設(shè)置
????unit?=?mat(ones((oS.m1)))??#[11...1].T
????print(“unit:\n“unit)
????I?=?eye(oS.m)
????print(“I:\n“I)
????zero?=?mat(zeros((11)))
????print(“unit:\n“zero)
????print(“zero.shape:“zero.shape)
????upmat?=?hstack((zerounit.T))
????print(“upmat:\n“upmat)
????print(“upmat:\n“upmat)
????downma

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-04-19?14:53??LSSVM_python_example\LSSVM_python_code_cherry\
?????文件??????280261??2018-11-18?21:10??LSSVM_python_example\LSSVM_python_code_cherry\Least?Squares?Sup-port?Vector?Machine?Classifiers.pdf
?????文件??????????19??2018-11-18?21:10??LSSVM_python_example\LSSVM_python_code_cherry\README.md
?????文件????????5840??2020-04-19?14:41??LSSVM_python_example\LSSVM_python_code_cherry\lssvm.py
?????文件????????2845??2018-11-18?21:10??LSSVM_python_example\LSSVM_python_code_cherry\testSetRBF.txt
?????目錄???????????0??2020-04-19?14:53??LSSVM_python_example\

評論

共有 條評論