亚洲精品久久久久久久久久久,亚洲国产精品一区二区制服,亚洲精品午夜精品,国产成人精品综合在线观看,最近2019中文字幕一页二页

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

adaboost運(yùn)行函數(shù)的算法怎么來(lái)的?基本程序代碼實(shí)現(xiàn)詳細(xì)

lviY_AI_shequ ? 2018-07-21 10:18 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

一.Adaboost理論部分

1.1 adaboost運(yùn)行過(guò)程

注釋:算法是利用指數(shù)函數(shù)降低誤差,運(yùn)行過(guò)程通過(guò)迭代進(jìn)行。其中函數(shù)的算法怎么來(lái)的,你不用知道!當(dāng)然你也可以嘗試使用其它的函數(shù)代替指數(shù)函數(shù),看看效果如何。

1.2 舉例說(shuō)明算法流程

1.3 算法誤差界的證明

注釋:誤差的上界限由Zm約束,然而Zm又是由Gm(xi)約束,所以選擇適當(dāng)?shù)腉m(xi)可以加快誤差的減小。

二.代碼實(shí)現(xiàn)

2.1程序流程圖

2.2基本程序?qū)崿F(xiàn)

注釋:真是倒霉玩意,本來(lái)代碼全部注釋好了,突然Ubuntu奔潰了,全部程序就GG了。。。下面的代碼就是官網(wǎng)的代碼,部分補(bǔ)上注釋?,F(xiàn)在使用Deepin桌面版了,其它方面都比Ubuntu好,但是有點(diǎn)點(diǎn)卡。

from numpy import *

def loadDataSet(fileName): #general function to parse tab -delimited floats

numFeat = len(open(fileName).readline().split(' ')) #get number of fields

dataMat = []; labelMat = []

fr = open(fileName)

for line in fr.readlines():

lineArr =[]

curLine = line.strip().split(' ')

for i in range(numFeat-1):

lineArr.append(float(curLine[i]))

dataMat.append(lineArr)

labelMat.append(float(curLine[-1]))

return dataMat,labelMat

def stumpClassify(dataMatrix,dimen,threshVal,threshIneq):#just classify the data

retArray = ones((shape(dataMatrix)[0],1))

if threshIneq == 'lt':

retArray[dataMatrix[:,dimen] <= threshVal] = -1.0

else:

retArray[dataMatrix[:,dimen] > threshVal] = -1.0

return retArray

def buildStump(dataArr,classLabels,D):

dataMatrix = mat(dataArr); labelMat = mat(classLabels).T

m,n = shape(dataMatrix)

numSteps = 10.0; bestStump = {}; bestClasEst = mat(zeros((m,1)))

minError = inf #init error sum, to +infinity

for i in range(n):#loop over all dimensions

rangeMin = dataMatrix[:,i].min(); rangeMax = dataMatrix[:,i].max();

stepSize = (rangeMax-rangeMin)/numSteps

for j in range(-1,int(numSteps)+1):#loop over all range in current dimension

for inequal in ['lt', 'gt']: #go over less than and greater than

threshVal = (rangeMin + float(j) * stepSize)

predictedVals = stumpClassify(dataMatrix,i,threshVal,inequal)#call stump classify with i, j, lessThan

errArr = mat(ones((m,1)))

errArr[predictedVals == labelMat] = 0

weightedError = D.T*errArr #calc total error multiplied by D

#print "split: dim %d, thresh %.2f, thresh ineqal: %s, the weighted error is %.3f" % (i, threshVal, inequal, weightedError)

if weightedError < minError:

minError = weightedError

bestClasEst = predictedVals.copy()

bestStump['dim'] = i

bestStump['thresh'] = threshVal

bestStump['ineq'] = inequal

return bestStump,minError,bestClasEst

def adaBoostTrainDS(dataArr,classLabels,numIt=40):

weakClassArr = []

m = shape(dataArr)[0]

D = mat(ones((m,1))/m) #init D to all equal

aggClassEst = mat(zeros((m,1)))

for i in range(numIt):

bestStump,error,classEst = buildStump(dataArr,classLabels,D)#build Stump

#print "D:",D.T

alpha = float(0.5*log((1.0-error)/max(error,1e-16)))#calc alpha, throw in max(error,eps) to account for error=0

bestStump['alpha'] = alpha

weakClassArr.append(bestStump) #store Stump Params in Array

#print "classEst: ",classEst.T

expon = multiply(-1*alpha*mat(classLabels).T,classEst) #exponent for D calc, getting messy

D = multiply(D,exp(expon)) #Calc New D for next iteration

D = D/D.sum()

#calc training error of all classifiers, if this is 0 quit for loop early (use break)

aggClassEst += alpha*classEst

#print "aggClassEst: ",aggClassEst.T

aggErrors = multiply(sign(aggClassEst) != mat(classLabels).T,ones((m,1)))

errorRate = aggErrors.sum()/m

print ("total error: ",errorRate)

if errorRate == 0.0: break

return weakClassArr,aggClassEst

def adaClassify(datToClass,classifierArr):

dataMatrix = mat(datToClass)#do stuff similar to last aggClassEst in adaBoostTrainDS

m = shape(dataMatrix)[0]

aggClassEst = mat(zeros((m,1)))

for i in range(len(classifierArr)):

classEst = stumpClassify(dataMatrix,classifierArr[i]['dim'],

classifierArr[i]['thresh'],

classifierArr[i]['ineq'])#call stump classify

aggClassEst += classifierArr[i]['alpha']*classEst

#print aggClassEst

return sign(aggClassEst)

def plotROC(predStrengths, classLabels):

import matplotlib.pyplot as plt

cur = (1.0,1.0) #cursor

ySum = 0.0 #variable to calculate AUC

numPosClas = sum(array(classLabels)==1.0)#標(biāo)簽等于1的和(也等于個(gè)數(shù))

yStep = 1/float(numPosClas); xStep = 1/float(len(classLabels)-numPosClas)

sortedIndicies = predStrengths.argsort()#get sorted index, it's reverse

sortData = sorted(predStrengths.tolist()[0])

fig = plt.figure()

fig.clf()

ax = plt.subplot(111)

#loop through all the values, drawing a line segment at each point

for index in sortedIndicies.tolist()[0]:

if classLabels[index] == 1.0:

delX = 0; delY = yStep;

else:

delX = xStep; delY = 0;

ySum += cur[1]

#draw line from cur to (cur[0]-delX,cur[1]-delY)

ax.plot([cur[0],cur[0]-delX],[cur[1],cur[1]-delY], c='b')

cur = (cur[0]-delX,cur[1]-delY)

ax.plot([0,1],[0,1],'b--')

plt.xlabel('False positive rate'); plt.ylabel('True positive rate')

plt.title('ROC curve for AdaBoost horse colic detection system')

ax.axis([0,1,0,1])

plt.show()

print ("the Area Under the Curve is: ",ySum*xStep)

注釋:重點(diǎn)說(shuō)明一下非均衡分類的圖像繪制問題,想了很久才想明白!

都是相對(duì)而言的,其中本文說(shuō)的曲線在左上方就為好,也是相對(duì)而言的,看你怎么定義個(gè)理解!

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 算法
    +關(guān)注

    關(guān)注

    23

    文章

    4750

    瀏覽量

    96989
  • 代碼
    +關(guān)注

    關(guān)注

    30

    文章

    4932

    瀏覽量

    72824

原文標(biāo)題:《機(jī)器學(xué)習(xí)實(shí)戰(zhàn)》AdaBoost算法(手稿+代碼)

文章出處:【微信號(hào):AI_shequ,微信公眾號(hào):人工智能愛好者社區(qū)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    復(fù)雜的軟件算法硬件IP核的實(shí)現(xiàn)

    獨(dú)立的 START 信號(hào) 用于控制該對(duì)象是否開始運(yùn)行以及用于指示操作完成的 DONE 信號(hào)。函數(shù)的參數(shù)以及返回值則作為該對(duì)象的輸入輸出信號(hào)。 3.HDL 文件生成 軟件算法
    發(fā)表于 10-30 07:02

    TCORDIC算法實(shí)現(xiàn)正余弦函數(shù)

    TCORDIC算法,由低延遲CORDIC算法和Taylor展開組成。Taylor展開計(jì)算作為CORDIC算法的補(bǔ)充,能夠結(jié)合CORDIC算法和Taylor展開方式
    發(fā)表于 10-29 06:30

    使用Nuclei Studio IDE計(jì)算程序運(yùn)行時(shí)間

    時(shí)間函數(shù)_gettimeofday()的系統(tǒng)時(shí)間,該函數(shù)的C語(yǔ)言代碼如下所示: 由C代碼可知,tp存儲(chǔ)了兩個(gè)變量tv_sec和tv_usec,前者代表秒數(shù)s,后者表示微秒us,在想要
    發(fā)表于 10-28 08:25

    查找表與多項(xiàng)式近似算法實(shí)現(xiàn)初等函數(shù)

    逼近的定義區(qū)間長(zhǎng)度及選取系數(shù)的方式?jīng)Q定。 每個(gè)子間隔的系數(shù)存儲(chǔ)在查找表中。用Xm來(lái)選擇系數(shù),所以方程變成: 使用查找表與多項(xiàng)式近似結(jié)合算法實(shí)現(xiàn)對(duì)數(shù)函數(shù),如下圖所示為指數(shù)
    發(fā)表于 10-28 08:10

    如何使用恢復(fù)算法來(lái)實(shí)現(xiàn)開平方運(yùn)算

    本文主要描述如何使用恢復(fù)算法來(lái)實(shí)現(xiàn)開平方運(yùn)算。 簡(jiǎn)介 開平方的恢復(fù)算法其實(shí)與除法的恢復(fù)算法十分相似。首先我們假設(shè)X為輸入的操作數(shù)(它應(yīng)該為
    發(fā)表于 10-24 13:33

    當(dāng)ICE_DAT引腳和ICE_CLK引腳在應(yīng)用程序代碼中配置為備用功能時(shí),是否會(huì)導(dǎo)致編程失???

    當(dāng)ICE_DAT引腳和ICE_CLK引腳在應(yīng)用程序代碼中配置為備用功能時(shí),是否會(huì)導(dǎo)致編程失???
    發(fā)表于 08-25 06:55

    嵌入式系統(tǒng)中,F(xiàn)LASH 中的程序代碼必須搬到 RAM 中運(yùn)行嗎?

    嵌入式系統(tǒng)里,F(xiàn)LASH 中的程序代碼并非必須搬到 RAM 中運(yùn)行,這得由硬件配置、實(shí)際性能需求和應(yīng)用場(chǎng)景共同決定。就像很多低端單片機(jī),無(wú)論是依賴片內(nèi) Flash 還是外掛的 SPI NOR
    的頭像 發(fā)表于 08-06 10:19 ?1056次閱讀
    嵌入式系統(tǒng)中,F(xiàn)LASH 中的<b class='flag-5'>程序代碼</b>必須搬到 RAM 中<b class='flag-5'>運(yùn)行</b>嗎?

    詳解hal_entry入口函數(shù)

    當(dāng)使用RTOS時(shí),程序從main函數(shù)開始進(jìn)行線程調(diào)度;當(dāng)沒有使用RTOS時(shí),C語(yǔ)言程序的入口函數(shù)main函數(shù)調(diào)用了hal_entry
    的頭像 發(fā)表于 07-25 15:34 ?1537次閱讀

    請(qǐng)問如何創(chuàng)建在 RAM 區(qū)域完全獨(dú)立運(yùn)行的閃存驅(qū)動(dòng)程序代碼?

    我在開發(fā)閃存驅(qū)動(dòng)程序代碼時(shí)遇到了一個(gè)問題。我將準(zhǔn)備好的HEX文件寫入指定的RAM區(qū)域,并嘗試使用指針調(diào)用,但調(diào)用失敗,無(wú)法正常擦除或?qū)懭?。?duì)于flash的操作代碼已經(jīng)通過(guò)了單獨(dú)的測(cè)試,為了使其更加
    發(fā)表于 07-25 07:33

    基于FPGA的壓縮算法加速實(shí)現(xiàn)

    的速度。我們將首先使用C語(yǔ)言進(jìn)行代碼實(shí)現(xiàn),然后在Vivado HLS中綜合實(shí)現(xiàn),并最終在FPGA板(pynq-z2)上進(jìn)行硬件實(shí)現(xiàn),同時(shí)于jupyter notebook中使用pyth
    的頭像 發(fā)表于 07-10 11:09 ?1952次閱讀
    基于FPGA的壓縮<b class='flag-5'>算法</b>加速<b class='flag-5'>實(shí)現(xiàn)</b>

    OptiSystem應(yīng)用:用MATLAB組件實(shí)現(xiàn)振幅調(diào)制

    。我們用MATLAB代碼控制電脈沖對(duì)光信號(hào)的調(diào)制過(guò)程,通過(guò)在MATLAB組件中導(dǎo)入MATLAB代碼來(lái)實(shí)現(xiàn)。整體光路圖如圖1,全局參數(shù)如圖2: 圖1.整體光路圖 圖2.全局參數(shù) 二、
    發(fā)表于 06-13 08:46

    18個(gè)常用的強(qiáng)化學(xué)習(xí)算法整理:從基礎(chǔ)方法到高級(jí)模型的理論技術(shù)與代碼實(shí)現(xiàn)

    本來(lái)轉(zhuǎn)自:DeepHubIMBA本文系統(tǒng)講解從基本強(qiáng)化學(xué)習(xí)方法到高級(jí)技術(shù)(如PPO、A3C、PlaNet等)的實(shí)現(xiàn)原理與編碼過(guò)程,旨在通過(guò)理論結(jié)合代碼的方式,構(gòu)建對(duì)強(qiáng)化學(xué)習(xí)算法的全面理解。為確保內(nèi)容
    的頭像 發(fā)表于 04-23 13:22 ?1161次閱讀
    18個(gè)常用的強(qiáng)化學(xué)習(xí)<b class='flag-5'>算法</b>整理:從基礎(chǔ)方法到高級(jí)模型的理論技術(shù)與<b class='flag-5'>代碼</b><b class='flag-5'>實(shí)現(xiàn)</b>

    RAKsmart企業(yè)服務(wù)器上部署DeepSeek編寫運(yùn)行代碼

    在RAKsmart企業(yè)服務(wù)器上部署并運(yùn)行DeepSeek模型的代碼示例和詳細(xì)步驟。假設(shè)使用 Python + Transformers庫(kù) + FastAPI實(shí)現(xiàn)一個(gè)基礎(chǔ)的AI服務(wù)。主機(jī)
    的頭像 發(fā)表于 03-25 10:39 ?479次閱讀

    關(guān)于cc2541程序代碼樣例

    CC2541哪里有cc2541的模數(shù)轉(zhuǎn)換模塊和藍(lán)牙模塊的程序代碼樣例呀?初學(xué)不懂
    發(fā)表于 01-20 07:14

    【RA-Eco-RA2E1-48PIN-V1.0開發(fā)板試用】原創(chuàng)測(cè)量代碼運(yùn)行時(shí)間

    詳細(xì)說(shuō)明。最后通過(guò)串口打印輸出算法模塊函數(shù)的執(zhí)行時(shí)間,來(lái)展示給大家。 1.打開我之前的項(xiàng)目工程FPU文件夾目錄,打開keil 打開pack insall 安裝管理器,安裝perf_c
    發(fā)表于 11-06 15:32