python - printing decision boundary with pyplot -
using pandas , sklearn create decision tree learn on data pruning method tree retry different max depths. believe have working cannot seem output via pyplot. can me
import numpy np import pandas pd sklearn import tree sklearn import cross_validation sklearn.cross_validation import kfold import matplotlib.pyplot plt features = ['birad','age','shape','margin','density','severity'] df = pd.read_csv('mammographic_masses.data',header=none,names=features) df= df[df.birad != '?'] df= df[df.age != '?'] df= df[df.shape != '?'] df= df[df.margin != '?'] df= df[df.density != '?'] #df= df[df.severity != '?'] x = df[features[:-1]] y = df['severity'] x_train,x_test,y_train,y_test = cross_validation.train_test_split(x,y,test_size=0.4,random_state=0) depth = [] best_depth = 3 best_score = 0 best_clf = [] in range(1,20): clf = tree.decisiontreeclassifier(max_depth=i) clf = clf.fit(x_train,y_train) scores = cross_validation.cross_val_score(clf,x_train,y_train,cv=10) ascore = clf.score(x_test,y_test) depth.append((i,clf.score(x_test,y_test))) if ascore > best_score: best_score,best_depth = ascore,i best_clf.append(clf) print best_depth,' ',best_score
just guess, since didn't show trying plot data: did call
plt.show()
after generating plots? won't displayed until that.
Comments
Post a Comment