中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

招聘網(wǎng)站源碼下載色盲測(cè)試圖

招聘網(wǎng)站源碼下載,色盲測(cè)試圖,如何在國(guó)稅網(wǎng)站做票種核定,網(wǎng)站開(kāi)發(fā)都是用什么做的任務(wù)描述 本關(guān)任務(wù):使用決策樹(shù)進(jìn)行分類 相關(guān)知識(shí) 為了完成本關(guān)任務(wù),你需要掌握:1.使用決策樹(shù)進(jìn)行分類 使用決策樹(shù)進(jìn)行分類 依靠訓(xùn)練數(shù)據(jù)構(gòu)造了決策樹(shù)之后,我們可以將它用于實(shí)際數(shù)據(jù)的分類。在執(zhí)行數(shù)據(jù)分類時(shí),需要…

任務(wù)描述

本關(guān)任務(wù):使用決策樹(shù)進(jìn)行分類

相關(guān)知識(shí)

為了完成本關(guān)任務(wù),你需要掌握:1.使用決策樹(shù)進(jìn)行分類

使用決策樹(shù)進(jìn)行分類

依靠訓(xùn)練數(shù)據(jù)構(gòu)造了決策樹(shù)之后,我們可以將它用于實(shí)際數(shù)據(jù)的分類。在執(zhí)行數(shù)據(jù)分類時(shí),需要決策樹(shù)以及用于構(gòu)造樹(shù)的標(biāo)簽向量。然后,程序比較測(cè)試數(shù)據(jù)與決策樹(shù)上的數(shù)值,遞歸執(zhí)行該過(guò)程直到進(jìn)人葉子節(jié)點(diǎn);最后將測(cè)試數(shù)據(jù)定義為葉子節(jié)點(diǎn)所屬的類型。 使用決策樹(shù)的分類函數(shù)如下:

  1. """
  2. Parameters:
  3. inputTree - 已經(jīng)生成的決策樹(shù)
  4. featLabels - 存儲(chǔ)選擇的最優(yōu)特征標(biāo)簽
  5. testVec - 測(cè)試數(shù)據(jù)列表,順序?qū)?yīng)最優(yōu)特征標(biāo)簽
  6. Returns:
  7. classLabel - 分類結(jié)果
  8. """
  9. # 函數(shù)說(shuō)明:使用決策樹(shù)分類
  10. def classify(inputTree, featLabels, testVec):
  11. firstStr = next(iter(inputTree)) #獲取決策樹(shù)結(jié)點(diǎn)
  12. secondDict = inputTree[firstStr] #下一個(gè)字典
  13. featIndex = featLabels.index(firstStr)
  14. for key in secondDict.keys():
  15. if testVec[featIndex] == key:
  16. if type(secondDict[key]).__name__ == 'dict':
  17. classLabel = classify(secondDict[key], featLabels, testVec)
  18. else: classLabel = secondDict[key]
  19. return classLabel

編程要求

根據(jù)提示,在右側(cè)編輯器補(bǔ)充代碼,運(yùn)用決策樹(shù)分類

測(cè)試說(shuō)明

平臺(tái)會(huì)對(duì)你編寫的代碼進(jìn)行測(cè)試:


開(kāi)始你的任務(wù)吧,祝你成功!

完整代碼如下:

# -*- coding: UTF-8 -*-
from math import log
import operator"""
Parameters:dataSet - 數(shù)據(jù)集
Returns:shannonEnt - 經(jīng)驗(yàn)熵(香農(nóng)熵)
"""
# 函數(shù)說(shuō)明:計(jì)算給定數(shù)據(jù)集的經(jīng)驗(yàn)熵(香農(nóng)熵)
def calcShannonEnt(dataSet):numEntires = len(dataSet)                       #返回?cái)?shù)據(jù)集的行數(shù)labelCounts = {}                               #保存每個(gè)標(biāo)簽(Label)出現(xiàn)次數(shù)的字典for featVec in dataSet:                        #對(duì)每組特征向量進(jìn)行統(tǒng)計(jì)currentLabel = featVec[-1]                 #提取標(biāo)簽(Label)信息if currentLabel not in labelCounts.keys(): #如果標(biāo)簽(Label)沒(méi)有放入統(tǒng)計(jì)次數(shù)的字典,添加進(jìn)去labelCounts[currentLabel] = 0labelCounts[currentLabel] += 1             #Label計(jì)數(shù)shannonEnt = 0.0                               #經(jīng)驗(yàn)熵(香農(nóng)熵)for key in labelCounts:                        #計(jì)算香農(nóng)熵prob = float(labelCounts[key]) / numEntires#選擇該標(biāo)簽(Label)的概率shannonEnt -= prob * log(prob, 2)          #利用公式計(jì)算return shannonEnt                              #返回經(jīng)驗(yàn)熵(香農(nóng)熵)"""
Parameters:無(wú)
Returns:dataSet - 數(shù)據(jù)集labels - 特征標(biāo)簽
"""
# 函數(shù)說(shuō)明:創(chuàng)建測(cè)試數(shù)據(jù)集
def createDataSet():dataSet = [[0, 0, 0, 0, 'no'],#數(shù)據(jù)集[0, 0, 0, 1, 'no'],[0, 1, 0, 1, 'yes'],[0, 1, 1, 0, 'yes'],[0, 0, 0, 0, 'no'],[1, 0, 0, 0, 'no'],[1, 0, 0, 1, 'no'],[1, 1, 1, 1, 'yes'],[1, 0, 1, 2, 'yes'],[1, 0, 1, 2, 'yes'],[2, 0, 1, 2, 'yes'],[2, 0, 1, 1, 'yes'],[2, 1, 0, 1, 'yes'],[2, 1, 0, 2, 'yes'],[2, 0, 0, 0, 'no']]labels = ['年齡', '有工作', '有自己的房子', '信貸情況']#特征標(biāo)簽return dataSet, labels#返回?cái)?shù)據(jù)集和分類屬性"""
Parameters:dataSet - 待劃分的數(shù)據(jù)集axis - 劃分?jǐn)?shù)據(jù)集的特征value - 需要返回的特征的值
Returns:無(wú)
"""
# 函數(shù)說(shuō)明:按照給定特征劃分?jǐn)?shù)據(jù)集
def splitDataSet(dataSet, axis, value):retDataSet = []                                #創(chuàng)建返回的數(shù)據(jù)集列表for featVec in dataSet:                        #遍歷數(shù)據(jù)集if featVec[axis] == value:reducedFeatVec = featVec[:axis]        #去掉axis特征reducedFeatVec.extend(featVec[axis+1:])#將符合條件的添加到返回的數(shù)據(jù)集retDataSet.append(reducedFeatVec)return retDataSet                              #返回劃分后的數(shù)據(jù)集"""
Parameters:dataSet - 數(shù)據(jù)集
Returns:bestFeature - 信息增益最大的(最優(yōu))特征的索引值
"""
# 函數(shù)說(shuō)明:選擇最優(yōu)特征
def chooseBestFeatureToSplit(dataSet):numFeatures = len(dataSet[0]) - 1                      #特征數(shù)量baseEntropy = calcShannonEnt(dataSet)                  #計(jì)算數(shù)據(jù)集的香農(nóng)熵bestInfoGain = 0.0                                     #信息增益bestFeature = -1                                       #最優(yōu)特征的索引值for i in range(numFeatures):                           #遍歷所有特征#獲取dataSet的第i個(gè)所有特征featList = [example[i] for example in dataSet]uniqueVals = set(featList)                         #創(chuàng)建set集合{},元素不可重復(fù)newEntropy = 0.0                                   #經(jīng)驗(yàn)條件熵for value in uniqueVals:                           #計(jì)算信息增益subDataSet = splitDataSet(dataSet, i, value)   #subDataSet劃分后的子集prob = len(subDataSet) / float(len(dataSet))   #計(jì)算子集的概率newEntropy += prob * calcShannonEnt(subDataSet)#根據(jù)公式計(jì)算經(jīng)驗(yàn)條件熵infoGain = baseEntropy - newEntropy                #信息增益# print("第%d個(gè)特征的增益為%.3f" % (i, infoGain))   #打印每個(gè)特征的信息增益if (infoGain > bestInfoGain):                      #計(jì)算信息增益bestInfoGain = infoGain                        #更新信息增益,找到最大的信息增益bestFeature = i                                #記錄信息增益最大的特征的索引值return bestFeature                                     #返回信息增益最大的特征的索引值"""
Parameters:classList - 類標(biāo)簽列表
Returns:sortedClassCount[0][0] - 出現(xiàn)此處最多的元素(類標(biāo)簽)
"""
# 函數(shù)說(shuō)明:統(tǒng)計(jì)classList中出現(xiàn)此處最多的元素(類標(biāo)簽)
def majorityCnt(classList):classCount = {}for vote in classList:                                        #統(tǒng)計(jì)classList中每個(gè)元素出現(xiàn)的次數(shù)if vote not in classCount.keys():classCount[vote] = 0classCount[vote] += 1sortedClassCount = sorted(classCount.items(), key = operator.itemgetter(1), reverse = True)#根據(jù)字典的值降序排序return sortedClassCount[0][0]                                #返回classList中出現(xiàn)次數(shù)最多的元素"""
Parameters:dataSet - 訓(xùn)練數(shù)據(jù)集labels - 分類屬性標(biāo)簽featLabels - 存儲(chǔ)選擇的最優(yōu)特征標(biāo)簽
Returns:myTree - 決策樹(shù)
"""
# 函數(shù)說(shuō)明:創(chuàng)建決策樹(shù)
def createTree(dataSet, labels, featLabels):classList = [example[-1] for example in dataSet]       #取分類標(biāo)簽(是否放貸:yes or no)if classList.count(classList[0]) == len(classList):    #如果類別完全相同則停止繼續(xù)劃分return classList[0]if len(dataSet[0]) == 1:                               #遍歷完所有特征時(shí)返回出現(xiàn)次數(shù)最多的類標(biāo)簽return majorityCnt(classList)bestFeat = chooseBestFeatureToSplit(dataSet)           #選擇最優(yōu)特征bestFeatLabel = labels[bestFeat]                       #最優(yōu)特征的標(biāo)簽featLabels.append(bestFeatLabel)myTree = {bestFeatLabel:{}}                            #根據(jù)最優(yōu)特征的標(biāo)簽生成樹(shù)del(labels[bestFeat])                                  #刪除已經(jīng)使用特征標(biāo)簽featValues = [example[bestFeat] for example in dataSet]#得到訓(xùn)練集中所有最優(yōu)特征的屬性值uniqueVals = set(featValues)                           #去掉重復(fù)的屬性值for value in uniqueVals:                               #遍歷特征,創(chuàng)建決策樹(shù)。myTree[bestFeatLabel][value] = createTree(splitDataSet(dataSet, bestFeat, value), labels, featLabels)return myTree"""
Parameters:inputTree - 已經(jīng)生成的決策樹(shù)featLabels - 存儲(chǔ)選擇的最優(yōu)特征標(biāo)簽testVec - 測(cè)試數(shù)據(jù)列表,順序?qū)?yīng)最優(yōu)特征標(biāo)簽
Returns:classLabel - 分類結(jié)果
"""
# 函數(shù)說(shuō)明:使用決策樹(shù)分類
def classify(inputTree, featLabels, testVec):firstStr = next(iter(inputTree))      #獲取決策樹(shù)結(jié)點(diǎn)secondDict = inputTree[firstStr]      #下一個(gè)字典featIndex = featLabels.index(firstStr)for key in secondDict.keys():if testVec[featIndex] == key:if type(secondDict[key]).__name__ == 'dict':classLabel = classify(secondDict[key], featLabels, testVec)else: classLabel = secondDict[key]return classLabelif __name__ == '__main__':##########請(qǐng)輸入你的代碼dataSet, labels = createDataSet()                      #得到數(shù)據(jù)集featLabels = []myTree = createTree(dataSet, labels, featLabels)       #創(chuàng)造樹(shù)testVec = [0,1]                                        #測(cè)試數(shù)據(jù)result = classify(myTree, featLabels, testVec)         #進(jìn)行分類#########if result == 'yes':print('放貸')if result == 'no':print('不放貸')

http://www.risenshineclean.com/news/45411.html

相關(guān)文章:

  • 精品課程網(wǎng)站建設(shè)論文重慶網(wǎng)站seo技術(shù)
  • 本地網(wǎng)站建設(shè)電話線上營(yíng)銷課程
  • 晉中網(wǎng)站開(kāi)發(fā)關(guān)鍵詞智能優(yōu)化排名
  • 申請(qǐng)一個(gè)域名可以做多少網(wǎng)站廣東seo外包服務(wù)
  • 專業(yè)網(wǎng)站制作設(shè)計(jì)公司哪家好sem培訓(xùn)班
  • 淄博市臨淄區(qū)建設(shè)局網(wǎng)站哪些網(wǎng)站推廣不收費(fèi)
  • 濰坊專業(yè)空心活塞桿win10優(yōu)化大師有用嗎
  • 天長(zhǎng)企業(yè)網(wǎng)站制作軟件開(kāi)發(fā)公司有哪些
  • 網(wǎng)站被人做跳轉(zhuǎn)了民生熱點(diǎn)新聞
  • app開(kāi)發(fā)和網(wǎng)站建設(shè)區(qū)別怎么注冊(cè)一個(gè)自己的網(wǎng)站
  • 怎么用電腦做網(wǎng)站寧波優(yōu)化系統(tǒng)
  • 校園網(wǎng)站建設(shè)的意義百度云官網(wǎng)登錄首頁(yè)
  • 深圳微信網(wǎng)站app拉新渠道
  • 做app網(wǎng)站制作上海牛巨微網(wǎng)絡(luò)科技有限公司
  • wordpress動(dòng)靜分離cdn深圳網(wǎng)站設(shè)計(jì)專業(yè)樂(lè)云seo
  • 石家莊學(xué)做網(wǎng)站建設(shè)培訓(xùn)學(xué)校百度關(guān)鍵詞優(yōu)化點(diǎn)擊 教程
  • 網(wǎng)站站內(nèi)鏈接奉化首頁(yè)的關(guān)鍵詞優(yōu)化
  • 鄭州專門做網(wǎng)站的公司seo百度關(guān)鍵字優(yōu)化
  • 畢業(yè)設(shè)計(jì)代做淘寶好還是網(wǎng)站好免費(fèi)注冊(cè)
  • 網(wǎng)絡(luò)公司+網(wǎng)站建設(shè)+小程序百度企業(yè)官網(wǎng)
  • 承接各類網(wǎng)站建設(shè)關(guān)鍵詞排名代發(fā)
  • 如何建立微網(wǎng)站詳細(xì)步驟廣東公司搜索seo哪家強(qiáng)
  • 佛山新網(wǎng)站制作怎么樣抖音優(yōu)化是什么意思
  • 安徽專業(yè)網(wǎng)站建設(shè)大全推薦寧波seo排名費(fèi)用
  • 公司網(wǎng)站服務(wù)器托管東莞網(wǎng)站排名推廣
  • 企業(yè)網(wǎng)站哪里可以做江西seo推廣方案
  • 煙臺(tái)市委網(wǎng)站企業(yè)網(wǎng)站的推廣方法有哪些
  • 酒店為什么做網(wǎng)站軟件外包公司有前途嗎
  • 網(wǎng)站安全檢測(cè)軟件網(wǎng)絡(luò)銷售公司怎么運(yùn)作
  • 鄭州易站通網(wǎng)站公司企業(yè)培訓(xùn)的目的和意義