决策树
from math import log
import pandas as pd
import numpy as np
from sklearn import tree
from six import StringIO
from sklearn.model_selection import train_test_split
from sklearn.metrics import auc, roc_curve
from numpy.lib.function_base import interp
from matplotlib import pyplot as plt
from itertools import cycle
def createdata():
df=pd.read_csv('datac.csv',usecols=[0,1,2,3,4,5,6,7,8,9,10])
return df
def showtree_pdf(data):
from sklearn import tree
import pydotplus
a = data.iloc[:,:9]
b = data.iloc[:,-1]
X_train, X_test, y_train, y_test = train_test_split(a, b, test_size=.01,random_state=4)
clf = tree.DecisionTreeClassifier()
clf.fit(X_train,y_train)
p=clf.feature_importances_
print(p)
dot_data = tree.export_graphviz(clf, out_file=None)
graph = pydotplus.graph_from_dot_data(dot_data)
graph.write_pdf("d3.pdf")
if __name__=="__main__":
data = createdata()
showtree_pdf(data)