济南高新区 网站建设公司,链接网站开发需要多少钱,深圳公司免费网站建设,网络系统中针对海量数据的加密1.下载2.安装#xff1a;双击3.创建桌面快捷方式安装目录\bin文件夹\#xff1a;找到gvedit.exe文件右键 发送到桌面快捷方式#xff0c;如下图#xff1a;4.配置环境变量将graphviz安装目录下的bin文件夹添加到Path环境变量中#xff1a;5.验证是否安装并配置成功进入win…1.下载2.安装双击3.创建桌面快捷方式安装目录\bin文件夹\找到gvedit.exe文件右键 发送到桌面快捷方式如下图4.配置环境变量将graphviz安装目录下的bin文件夹添加到Path环境变量中5.验证是否安装并配置成功进入windows命令行界面输入dot -version然后按回车如果显示graphviz的相关版本信息则安装配置成功。如图6.python环境中安装(pycharm中)File-Settings-Project:Python然后输入graphivz安装安装需要等待一会。。。。决策树实战代码# -*- coding:utf-8 -*-from sklearn.feature_extraction import DictVectorizerimport csvfrom sklearn import preprocessingfrom sklearn import treefrom sklearn.externals.six import StringIO#read the csv fileallElectronicsDate open(rD:\Python\date\AllElectronics.csv,rt)reader csv.reader(allElectronicsDate)headers next(reader)# headers reader.next()print(headers)#打印输出第一行标题#[RID, age, income, student, credit_rating, Class_buys_computer]featureList [] #用来存储特征值labelList [] #用来存储类标签#获取特征值并打印输出for row in reader:labelList.append(row[len(row) - 1])#每一行最后的值类标签rowDict {}for i in range(1,len(row) - 1):#每一行 遍历除第一列和最后一列的值rowDict[headers[i]] row[i]featureList.append(rowDict)print(featureList)#vectorize feature 使用sklearn自带的方法将特征值离散化为数字标记vec DictVectorizer()dummyX vec.fit_transform(featureList).toarray()print(dummyY: str(dummyX))print(vec.get_feature_names())# print(feature_name str(vec.get_feature_names()))print(labelList: str(labelList))#vectorize class labels #数字化类标签lb preprocessing.LabelBinarizer()dummyY lb.fit_transform(labelList)print(dummyY: str(dummyY))#use the decision tree for classificationclf tree.DecisionTreeClassifier(criterionentropy)clf clf.fit(dummyX,dummyY) #构建决策树#打印构建决策树采用的参数print(clf: str(clf))#visilize the modelwith open(allElectronicInformationGainOri.dot,w) as f:ftree.export_graphviz(clf,feature_namesvec.get_feature_names(),out_filef)#这时就生成了allElectronicInformationGainOri.dot文件# dot -Tpdf in.dot -o out.pdf dot文件输出为pdf文件#验证数据取出一行数据修改几个属性预测结果oneRowX dummyX[0,:]print(oneRowX: str(oneRowX))newRowX oneRowXnewRowX[0] 1newRowX[2] 0print(newRowX: str(newRowX))predictedY clf.predict(newRowX)print(predictedY:str(predictedY))结果[RID, age, income, student, credit_rating, class_buys_computer][{income: high, age: youth, student: no, credit_rating: fair}, {income: high, age: youth, student: no, credit_rating: excellent}, {income: high, age: middle_aged, student: no, credit_rating: fair}, {income: medium, age: senior, student: no, credit_rating: fair}, {income: low, age: senior, student: yes, credit_rating: fair}, {income: low, age: senior, student: yes, credit_rating: excellent}, {income: low, age: middle_aged, student: yes, credit_rating: excellent}, {income: medium, age: youth, student: no, credit_rating: fair}, {income: low, age: youth, student: yes, credit_rating: fair}, {income: medium, age: senior, student: yes, credit_rating: fair}, {income: medium, age: youth, student: yes, credit_rating: excellent}, {income: medium, age: middle_aged, student: no, credit_rating: excellent}, {income: high, age: middle_aged, student: yes, credit_rating: fair}, {income: medium, age: senior, student: no, credit_rating: excellent}]dummyY:[[ 0. 0. 1. 0. 1. 1. 0. 0. 1. 0.][ 0. 0. 1. 1. 0. 1. 0. 0. 1. 0.][ 1. 0. 0. 0. 1. 1. 0. 0. 1. 0.][ 0. 1. 0. 0. 1. 0. 0. 1. 1. 0.][ 0. 1. 0. 0. 1. 0. 1. 0. 0. 1.][ 0. 1. 0. 1. 0. 0. 1. 0. 0. 1.][ 1. 0. 0. 1. 0. 0. 1. 0. 0. 1.][ 0. 0. 1. 0. 1. 0. 0. 1. 1. 0.][ 0. 0. 1. 0. 1. 0. 1. 0. 0. 1.][ 0. 1. 0. 0. 1. 0. 0. 1. 0. 1.][ 0. 0. 1. 1. 0. 0. 0. 1. 0. 1.][ 1. 0. 0. 1. 0. 0. 0. 1. 1. 0.][ 1. 0. 0. 0. 1. 1. 0. 0. 0. 1.][ 0. 1. 0. 1. 0. 0. 0. 1. 1. 0.]][agemiddle_aged, agesenior, ageyouth, credit_ratingexcellent, credit_ratingfair, incomehigh, incomelow, incomemedium, studentno, studentyes]labelList:[no, no, yes, yes, yes, no, yes, no, yes, yes, yes, yes, yes, no]dummyY:[[0][0][1][1][1][0][1][0][1][1][1][1][1][0]]clf:DecisionTreeClassifier(class_weightNone, criterionentropy, max_depthNone,max_featuresNone, max_leaf_nodesNone, min_samples_leaf1,min_samples_split2, min_weight_fraction_leaf0.0,random_stateNone, splitterbest)oneRowX:[ 0. 0. 1. 0. 1. 1. 0. 0. 1. 0.]newRowX:[ 1. 0. 0. 0. 1. 1. 0. 0. 1. 0.]predictedY:[1]在项目路径里面打开dot文件将dot文件转化为直观的PDF文件(dos 里面输入dot -Tpdf D:\Python\机器学习\allElectronicInformationGainOri.dot -o D:\Python\机器学习\out.pdf 然后回车)dot -Tpdf D:\Python\机器学习\allElectronicInformationGainOri.dot -o D:\Python\机器学习\out.pdf