• 大小: 1.68MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-10
  • 语言: 其他
  • 标签: 机器学习  数据集  

资源简介

机器学习实战数据集

资源截图

代码片段和文件信息

#-*- coding:utf-8 _*-
“““
@author:KING
@file: adaboost.py
@time: 2018/08/15
“““

import numpy as np

def loadSimpData():
    datMat = np.matrix([[1.2.1]
                     [2.1.1]
                     [1.31.]
                     [1.1.]
                     [2.1.]])
    classLabels = [1.01.0-1.0-1.01.0]
    return datMatclassLabels

def stumpClassify(dataMatrixdimenthreshValthreshIneq):
    retArray = np.ones((np.shape(dataMatrix)[0]1))
    if threshIneq == ‘lt‘:
        retArray[dataMatrix[:dimen] <= threshVal] = -1.0
    else:
        retArray[dataMatrix[: dimen] > threshVal] = -1.0
    return retArray

def buildStump(dataArrclassLabelsD):
    dataMatrix = np.mat(dataArr)
    labelMat = np.mat(classLabels).T
    mn = np.shape(dataMatrix)
    numSteps = 10.0
    bestStump = {}
    bestClasEst = np.mat(np.zeros((m1)))
    minError = np.inf
    for i in range(n):#遍历特征
        rangeMin = dataMatrix[:i].min()
        rangeMax = dataMatrix[:i].max()
        stepSize = (rangeMax-rangeMin)/numSteps#阈值增长步长
        for j in range(-1int(numSteps)+1):
            for inequal in [‘lt‘‘gt‘]:
                threshVal = (rangeMin+float(j)*stepSize)
                predictedVals = stumpClassify(dataMatrixithreshValinequal)
                errArr = np.mat(np.ones((m1)))
                errArr[predictedVals==labelMat]=0
                weightedError = D.T*errArr
                print(“split:dim %dthresh %.2fthresh inequal:%sthe weightedError is :%.3f“ %(
                    ithreshValinequalweightedError))
                if weightedError                    minError = weightedError
                    bestClasEst = predictedVals.copy()
                    bestStump[‘dim‘] = i
                    bestStump[‘thresh‘]=threshVal
                    bestStump[‘ineq‘] = inequal
    return bestStumpminErrorbestClasEst

def adaBoostTrainDS(dataArrclassLabelsnumIt = 40):
    weakClassArr = []
    m = np.shape(dataArr)[0]
    D = np.mat(np.ones((m1))/m)
    aggClassEst = np.mat(np.zeros((m1)))
    for i in range(numIt):
        bestStumperrorclassEst = buildStump(dataArrclassLabelsD)#第i个弱分类器
        print(“D:“D.T)
        alpha = float(0.5*np.log((1.0-error)/np.fmax(error1e-16)))
        bestStump[‘alpha‘] = alpha
        weakClassArr.append(bestStump)
        print(“classEst: “classEst.T)#该分类器的分类结果
        expon = np.multiply(-1*alpha*np.mat(classLabels).TclassEst)
        D = np.multiply(Dnp.exp(expon))
        D = D/D.sum()
        aggClassEst+=alpha*classEst#与此前的分类器同时工作给出分类结果
        print(“aggClassEst: “aggClassEst.T)
        aggErrors = np.multiply(np.sign(aggClassEst)!= np.mat(classLabels).Tnp.ones((m1)))
        errorRate = aggErrors.sum()/m
        print(“total error:“errorRate“\n“)
        if errorRate == 0.0:
            break

    return weakClassArr

def adaClassify(dataToClassclassifierArr):
    dataMatrix = np.mat(dataToClass)
    m = np.shape(dataMatrix)[0]
    aggClassEst = np.mat(np.

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\.idea\
     文件         455  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\.idea\AdaBoost.iml
     文件         185  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\.idea\misc.xml
     文件         268  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\.idea\modules.xml
     文件        6905  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\.idea\workspace.xml
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\.ipynb_checkpoints\
     文件        6963  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\.ipynb_checkpoints\AdaBoost-checkpoint.ipynb
     文件        8412  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\AdaBoost.ipynb
     文件        3456  2018-08-15 07:18  Machine-Learning-in-Action-master\AdaBoost\adaboost.py
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\.idea\
     文件         398  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\.idea\Logistic回归.iml
     文件         185  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\.idea\misc.xml
     文件         280  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\.idea\modules.xml
     文件        9563  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\.idea\workspace.xml
     文件        3722  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\horseColicTest.txt
     文件       60357  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\horseColicTraining.txt
     文件        4007  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\logRegres.py
     文件        4507  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\logRegres.pyc
     文件        2087  2018-08-15 07:18  Machine-Learning-in-Action-master\Logistic回归\testSet.txt
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\MLiA_SourceCode\
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\MLiA_SourceCode\machinelearninginaction\
     文件          31  2018-08-15 07:18  Machine-Learning-in-Action-master\README.txt
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\SVM\
     目录           0  2018-08-15 07:18  Machine-Learning-in-Action-master\SVM\.idea\
     文件         398  2018-08-15 07:18  Machine-Learning-in-Action-master\SVM\.idea\SVM.iml
     文件         185  2018-08-15 07:18  Machine-Learning-in-Action-master\SVM\.idea\misc.xml
     文件         258  2018-08-15 07:18  Machine-Learning-in-Action-master\SVM\.idea\modules.xml
     文件       16956  2018-08-15 07:18  Machine-Learning-in-Action-master\SVM\.idea\workspace.xml
............此处省略3581个文件信息

评论

共有 条评论