• 大小: 17.29MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-31
  • 语言: 其他
  • 标签: 决策树  

资源简介

ID3算法及蘑菇数据集,幼儿园数据集 ID3算法及蘑菇数据集,幼儿园数据集 ID3算法及蘑菇数据集,幼儿园数据集

资源截图

代码片段和文件信息

import numpy as np
import copy
import pickle
from sklearn.model_selection import train_test_split


def storedata(datain filename):
    fw = open(filename ‘wb+‘)
    pickle.dump(datain fw protocol=-1)
    fw.close()


def grabdata(filename):
    fr = open(filename ‘rb+‘)
    return pickle.load(fr)


“““
def datasp(filename testfile trainfile percent):
    dataset = grabdata(filename)
    datasetnew = copy.deepcopy(dataset)
    for simple in dataset:
        if dataset.count(simple) != 1:
            datasetnew.remove(simple)
    splitdata = {}
    for simple in datasetnew:
        if simple[-1] not in splitdata.keys():
            data = []
            splitdata[simple[-1]] = data
            splitdata[simple[-1]].append(simple)
    testdata = []
    traindata = copy.deepcopy(datasetnew)
    for label in splitdata.keys():
        for simple in splitdata[label]:
            if np.random.randint(1 100) <= percent:
                testdata.append(simple)
                traindata.remove(simple)
    storedata(testdata testfile)
    storedata(traindata trainfile)

datasp(‘mushroomdata100_pickle.txt‘ ‘mushroomtest100_pickle.txt‘ ‘mushroomtrain100_pickle.txt‘ 70)
te = grabdata(‘mushroomtest100_pickle.txt‘)
tr = grabdata(‘mushroomtrain100_pickle.txt‘)
print(‘testdata:\n‘ len(te) ‘\n‘ te)
print(‘traindata:\n‘ len(tr) ‘\n‘ tr)
“““

dataset = grabdata(‘pickle_nursery.txt‘)
traindata testdata = train_test_split(dataset test_size=0.1 random_state=None stratify=None)
storedata(testdata ‘pickle_nurserytest.txt‘)
storedata(traindata ‘pickle_nurserytrain.txt‘)
print(testdata‘\n‘)
print(traindata ‘\n‘)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-05 22:15  ID3\
     目录           0  2017-09-05 22:13  ID3\ID3\
     目录           0  2017-09-05 22:14  ID3\ID3\.idea\
     文件         528  2017-08-30 21:15  ID3\ID3\.idea\ID3_03.iml
     目录           0  2017-09-03 20:48  ID3\ID3\.idea\inspectionProfiles\
     文件         404  2017-09-03 18:29  ID3\ID3\.idea\inspectionProfiles\Project_Default.xml
     文件         221  2017-08-30 21:15  ID3\ID3\.idea\misc.xml
     文件         264  2017-08-18 14:50  ID3\ID3\.idea\modules.xml
     文件       34573  2017-09-05 22:14  ID3\ID3\.idea\workspace.xml
     文件        1691  2017-09-05 22:02  ID3\ID3\datasplit.py
     文件         363  2017-09-05 22:06  ID3\ID3\pk.py
     文件        5905  2017-09-05 22:11  ID3\ID3\treeMake.py
     文件        4131  2017-09-02 15:04  ID3\ID3\treePlotter.py
     文件         764  2017-09-05 21:58  ID3\ID3\treeUse.py
     目录           0  2017-09-05 22:06  ID3\ID3\__pycache__\
     文件      309279  2017-09-03 16:29  ID3\ID3\__pycache__\pickle.cpython-36.pyc
     文件         477  2017-09-05 22:06  ID3\ID3\__pycache__\pk.cpython-36.pyc
     文件        2768  2017-09-02 15:04  ID3\ID3\__pycache__\treePlotter.cpython-36.pyc
     目录           0  2017-09-05 22:16  ID3\MLiA_SourceCode\
     目录           0  2017-09-05 22:15  ID3\MLiA_SourceCode\Ch02\
     文件       35725  2012-03-01 15:40  ID3\MLiA_SourceCode\Ch02\datingTestSet.txt
     文件       27067  2012-03-01 15:39  ID3\MLiA_SourceCode\Ch02\datingTestSet2.txt
     文件      739988  2011-05-04 15:43  ID3\MLiA_SourceCode\Ch02\digits.zip
     目录           0  2017-09-05 22:15  ID3\MLiA_SourceCode\Ch02\EXTRAS\
     文件        2052  2010-10-27 08:32  ID3\MLiA_SourceCode\Ch02\EXTRAS\createDist.py
     文件        2162  2011-05-31 10:56  ID3\MLiA_SourceCode\Ch02\EXTRAS\createDist2.py
     文件         561  2011-05-31 10:52  ID3\MLiA_SourceCode\Ch02\EXTRAS\createFirstPlot.py
     文件         522  2011-04-29 08:14  ID3\MLiA_SourceCode\Ch02\EXTRAS\README.txt
     文件           0  2010-10-27 08:42  ID3\MLiA_SourceCode\Ch02\EXTRAS\testSet.txt
     文件        4268  2011-05-31 11:45  ID3\MLiA_SourceCode\Ch02\kNN.py
     文件        4500  2011-05-31 11:07  ID3\MLiA_SourceCode\Ch02\kNN.pyc
............此处省略211个文件信息

评论

共有 条评论