chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

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

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

3天內不再提示

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

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

掃碼添加小助手

加入工程師交流群

一.Adaboost理論部分

1.1 adaboost運行過程

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

1.2 舉例說明算法流程

1.3 算法誤差界的證明

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

二.代碼實現(xiàn)

2.1程序流程圖

2.2基本程序實現(xiàn)

注釋:真是倒霉玩意,本來代碼全部注釋好了,突然Ubuntu奔潰了,全部程序就GG了。。。下面的代碼就是官網(wǎng)的代碼,部分補上注釋?,F(xiàn)在使用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的和(也等于個數(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)

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

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

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

    關注

    23

    文章

    4740

    瀏覽量

    96730
  • 代碼
    +關注

    關注

    30

    文章

    4922

    瀏覽量

    72258

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

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

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

掃碼添加小助手

加入工程師交流群

    評論

    相關推薦
    熱點推薦

    當ICE_DAT引腳和ICE_CLK引腳在應用程序代碼中配置為備用功能時,是否會導致編程失???

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

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

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

    詳解hal_entry入口函數(shù)

    當使用RTOS時,程序從main函數(shù)開始進行線程調度;當沒有使用RTOS時,C語言程序的入口函數(shù)main函數(shù)調用了hal_entry
    的頭像 發(fā)表于 07-25 15:34 ?1466次閱讀

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

    我在開發(fā)閃存驅動程序代碼時遇到了一個問題。我將準備好的HEX文件寫入指定的RAM區(qū)域,并嘗試使用指針調用,但調用失敗,無法正常擦除或寫入。對于flash的操作代碼已經通過了單獨的測試,為了使其更加
    發(fā)表于 07-25 07:33

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

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

    OptiSystem應用:用MATLAB組件實現(xiàn)振幅調制

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

    18個常用的強化學習算法整理:從基礎方法到高級模型的理論技術與代碼實現(xiàn)

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

    部署計算機上運行 LabVIEW 應用程序時出現(xiàn)以下錯誤: “缺少外部函數(shù) dll...”解決辦法

    如果你既有 DLL 文件,也有頭 (.h) 文件,那么可以使用共享庫批量生成VI,不用再一個一個使用“調用庫函數(shù)節(jié)點”調用DLL,源代碼運行是沒有問題,一旦生成應用
    發(fā)表于 04-01 19:10

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

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

    OptiSystem應用:用MATLAB組件實現(xiàn)振幅調制

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

    關于cc2541程序代碼樣例

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

    基于NXP MCXA153 MCU實現(xiàn)RT-Thread的MTD NOR Flash驅動

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

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

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

    基于圖遍歷的Flink任務畫布模式下零代碼開發(fā)實現(xiàn)方案

    的過程。以下是利用Flink的 StreamGraph 通過低代碼的方式,實現(xiàn)StreamGraph的生成,并最終實現(xiàn) Flink 程序
    的頭像 發(fā)表于 11-05 10:35 ?1249次閱讀
    基于圖遍歷的Flink任務畫布模式下零<b class='flag-5'>代碼</b>開發(fā)<b class='flag-5'>實現(xiàn)</b>方案

    Pure path studio內能否自己創(chuàng)建一個component,實現(xiàn)特定的算法,例如LMS算法?

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