在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

adaboost運行函數的算法怎么來的?基本程序代碼實現詳細

lviY_AI_shequ ? 2018-07-21 10:18 ? 次閱讀

一.Adaboost理論部分

1.1 adaboost運行過程

注釋:算法是利用指數函數降低誤差,運行過程通過迭代進行。其中函數的算法怎么來的,你不用知道!當然你也可以嘗試使用其它的函數代替指數函數,看看效果如何。

1.2 舉例說明算法流程

1.3 算法誤差界的證明

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

二.代碼實現

2.1程序流程圖

2.2基本程序實現

注釋:真是倒霉玩意,本來代碼全部注釋好了,突然Ubuntu奔潰了,全部程序就GG了。。。下面的代碼就是官網的代碼,部分補上注釋。現在使用Deepin桌面版了,其它方面都比Ubuntu好,但是有點點卡。

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)#標簽等于1的和(也等于個數)

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)

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

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

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 算法
    +關注

    關注

    23

    文章

    4632

    瀏覽量

    93454
  • 代碼
    +關注

    關注

    30

    文章

    4841

    瀏覽量

    69169

原文標題:《機器學習實戰》AdaBoost算法(手稿+代碼)

文章出處:【微信號:AI_shequ,微信公眾號:人工智能愛好者社區】歡迎添加關注!文章轉載請注明出處。

收藏 人收藏

    評論

    相關推薦

    OptiSystem應用:用MATLAB組件實現振幅調制

    。我們用MATLAB代碼控制電脈沖對光信號的調制過程,通過在MATLAB組件中導入MATLAB代碼實現。整體光路圖如圖1,全局參數如圖2: 圖1.整體光路圖 圖2.全局參數 二、
    發表于 02-14 09:39

    關于cc2541程序代碼樣例

    CC2541哪里有cc2541的模數轉換模塊和藍牙模塊的程序代碼樣例呀?初學不懂
    發表于 01-20 07:14

    基于NXP MCXA153 MCU實現RT-Thread的MTD NOR Flash驅動

    在嵌入式系統中,片上Flash存儲器是一個關鍵組件,用于存儲程序代碼和關鍵數據。本文將詳細介紹如何在NXPMCXA153 MCU上實現RT-Thread的MTD (Memory Technology Device) NOR Fl
    的頭像 發表于 11-09 14:00 ?665次閱讀
    基于NXP MCXA153 MCU<b class='flag-5'>實現</b>RT-Thread的MTD NOR Flash驅動

    【RA-Eco-RA2E1-48PIN-V1.0開發板試用】原創測量代碼運行時間

    詳細說明。最后通過串口打印輸出算法模塊函數的執行時間,展示給大家。 1.打開我之前的項目工程FPU文件夾目錄,打開keil 打開pack insall 安裝管理器,安裝perf_c
    發表于 11-06 15:32

    Pure path studio內能否自己創建一個component,實現特定的算法,例如LMS算法

    TLV320AIC3254EVM-K評估模塊, Pure path studio軟件開發環境。 問題:1.Pure path studio 內能否自己創建一個component,實現特定的算法
    發表于 11-01 08:25

    單片機燒錄程序的線比單片機上的少還能燒錄嗎

    單片機燒錄原理 單片機燒錄是指將編寫好的程序代碼通過一定的方式傳輸到單片機的存儲器中,使其能夠按照程序的指令運行。這個過程通常需要使用燒錄器或者編程器等設備,通過一定的接口與單片機進行通信。 單片機
    的頭像 發表于 09-02 09:54 ?630次閱讀

    LKT(LCS)代碼移植芯片優勢

    所謂代碼移植就是客戶可以把自定義的程序一部分關鍵代碼函數移植到加密芯片中運行。用戶采用標準C語言編寫代碼
    的頭像 發表于 08-22 10:03 ?884次閱讀

    怎樣用Arduino測試鋰電池容量

    本文詳細介紹了如何用Arduino測量鋰電池的容量。并附有電路圖和Arduino的程序代碼
    的頭像 發表于 07-30 09:14 ?1077次閱讀
    怎樣用Arduino測試鋰電池容量

    ESP32C3通過QSPI flash片外運行代碼,如果頻繁地存儲錄音音頻數據,會影響程序運行嗎?

    ESP32C3通過QSPI flash 片外運行代碼,如果頻繁地存儲錄音音頻數據,會影響程序運行嗎?有這個風險嗎?
    發表于 06-20 08:28

    運動控制器的代碼運行順序是什么

    運動控制器是一種用于控制機械運動的設備,它可以接收輸入信號并根據這些信號控制機械的運動。運動控制器的代碼運行順序對于實現精確的運動控制至關重要。本文將詳細介紹運動控制器的
    的頭像 發表于 06-13 09:25 ?559次閱讀

    探討AI編寫代碼技術,以及提高代碼質量的關鍵:靜態代碼分析工具Perforce Helix QAC &amp; Klocwork

    的過程,并回答這個問題: AI會取代程序員嗎? 什么是AI代碼生成? 近年來,生成式AI的應用呈爆炸式增長,這主要因為現在有足夠的計算能力運行深度學習
    的頭像 發表于 06-05 14:10 ?475次閱讀

    在stm32的運行程序中,初始函數明明沒有在while函數里面,為什么能反復運行

    在stm32的運行程序中,好多初始函數明明沒有在while函數里面,但是,他卻能反復的,不斷地去運行,這是為什么呢? 就像是這個程序,對于設
    發表于 04-08 08:15

    使用STM32CubeMX初始化STM32F103程序代碼默認打開了哪些中斷?是否可以暫時性關閉?

    使用STM32CubeMX初始化STM32F103程序代碼,在不使用任何外設中斷的情況下,系統會默認打開哪些中斷?這些中斷又可以怎樣暫時性關閉?
    發表于 03-11 07:22

    verilog function函數的用法

    Verilog 中被廣泛用于對電路進行模塊化設計,以簡化和組織代碼。 本文將詳細介紹 Verilog 函數的用法,并探討函數在硬件設計中的重要性和實際應用場景。 一. Verilog
    的頭像 發表于 02-22 15:49 ?6134次閱讀

    如何使用exit()、_exit()和_Exit()終止程序運行呢?

    在Linux系統下,你可以使用 exit()、_exit() 和 _Exit() 終止程序運行,特別是在出現錯誤或執行失敗的情況下。
    的頭像 發表于 02-22 12:20 ?1021次閱讀
    主站蜘蛛池模板: 午夜小视频在线观看 | 在线观看免费观看 | 中文字幕第8页 | 国产hs免费高清在线观看 | 欧美很很干 | 香蕉视频在线免费播放 | 非常黄的网站 | 男人的天堂网在线 | 最新毛片网 | 成人男女啪啪免费观看网站 | 91精品久久国产青草 | 中国三级视频 | 亚洲精品中文字幕乱码三区一二 | 欧美日韩精品一区二区在线线 | 午夜黄色大片 | 一本一本大道香蕉久在线精品 | 深爱五月激情五月 | 四虎精品影院4hutv四虎 | www.天天干.com| 色综合狠狠 | 国产片无遮挡在线看床戏 | 婷婷激情五月综合 | 欧美中出在线 | 欧美一区高清 | 欧美中字| 久久久久国产精品 | 午夜一级黄色片 | 黄黄的网站在线观看 | 午夜久久精品 | 亚洲区 | 91大神免费视频 | 男女午夜免费视频 | 亚洲一区二区三区四区在线 | 亚洲第一香蕉视频 | 午夜久久久久久亚洲国产精品 | 国产片一级特黄aa的大片 | 狼干综合 | 免费jyzzjyzz在线播放大全 | 国产nv精品你懂得 | 国产性做久久久久久 | 国产精品国产三级在线高清观看 |