首页 > 编程知识 正文

python决策树预测模型,决策树分类的基本原理

时间:2023-05-05 02:51:47 阅读:59260 作者:3162

似乎没有将数据集分成单独的培训和测试数据集。 因此,分类器可能过度适合数据集,无法成功处理数据集外部的样本。 在

随机选择75%的数据进行训练,用剩下的25%试着测试精度。 例如,替换代码的最后一部分: import random

数据集,labels=load _ CSV (data/basketball.train.CSV ) )。

random.shuffle (数据) )。

split_index=int(len(dataset ) * 0.75 ) ) ) ) ) ) ) )。

train _ dataset=dataset [ : split _ index ]

test _ dataset=dataset [ split _ index : ]

(我的树=创建树(train _ dataset,labels ) ) ) ) ) ) ) ) )

predictions=[]

for row in test_dataset:

prediction=classify (我的树、['location '、' w '、' final_margin '、' shot_number '、' period '、' game _ cl

' shot_dist '、' pts_type '、' close_def_dist'] ' '、[row[0]、row[1]、row[2]、row[3]、和row [ 4

row[9]、row[10]、row[11] )

#print('expected=%s,got=%s'% ) row[-1],prediction ) )

predictions.append(prediction )

actual=[ row [-1 ] forrowintest _ dataset ]

accuracy=accuracy _ metric (actual,predictions )。

打印(访问)

(注)未测试) ) ) )。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。