亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標題:
決策樹實現python程序
[打印本頁]
作者:
suncaixin
時間:
2018-2-1 15:54
標題:
決策樹實現python程序
利用python實現決策時程序,最后輸出整個決策過程的pdf文件
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 22 13:13:07 2017
@author: suncaixin
"""
#collect number
from sklearn.feature_extraction import DictVectorizer
import numpy as np
import pandas as pd
import csv
from sklearn import tree
from sklearn import preprocessing
allElectrionicsData=open(r'數據地址','rt')
reader=csv.reader(allElectrionicsData)
headers=next(reader)
print(headers)
feature_list=[]
label_list=[]
for row in reader:
label_list.append(row[len(row)-1])
rowDict={}
for i in range(1,len(row)-1):
print(row[i])
rowDict[headers[i]]=row[i]
print('rowDict:',rowDict)
feature_list.append(rowDict)
print(feature_list)
#tranform feature
vec=DictVectorizer()
dunmyX=vec.fit_transform(feature_list).toarray()
print('dunmyX:',str(dunmyX))
print(vec.get_feature_names())
#class label transform
lb=preprocessing.LabelBinarizer()
dunmyY=lb.fit_transform(label_list)
print('dunmyY:',str(dunmyY))
#decision tree
clf=tree.DecisionTreeClassifier(criterion='entropy')
clf=clf.fit(dunmyX,dunmyY)
print('clf',str(clf))
#visulize model
with open('allElectronicInformationGain.dot','w') as f:
f=tree.export_graphviz(clf,feature_names=vec.get_feature_names(),out_file=f)
#output pdf:dot -Tpdf C:\Users\suncaixin\allElectronicInformationGain.dot -o outpu.pdf
#predict
oneRowx=dunmyX[0,:]
newRowx=oneRowx
newRowx[0]=1
newRowx[2]=0
predictedY=clf.predict([newRowx])
print('predicted:',str(predictedY))
復制代碼
decision_tree.zip
2018-2-1 15:54 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
884 Bytes, 下載次數: 7, 下載積分: 黑幣 -5
決策樹python程序
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1