Created
February 15, 2019 17:59
-
-
Save vnkdj5/0df12f16de23385574d667197ebee0bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sklearn | |
import numpy as np | |
import pandas as pd | |
buy = pd.read_csv('buys.csv') | |
from sklearn.model_selection import train_test_split | |
from sklearn.tree import DecisionTreeClassifier | |
x_fe=['age','income','gender','marital_status'] | |
x=buy[x_fe] | |
y=buy['buys'] | |
from sklearn import preprocessing | |
x=x.apply(preprocessing.LabelEncoder().fit_transform) | |
print(x) | |
clf = DecisionTreeClassifier(criterion='entropy') | |
model = clf.fit(x,y) | |
from IPython.display import Image | |
from sklearn import tree | |
import pydotplus | |
dot_data = tree.export_graphviz(model, out_file=None, | |
feature_names=x_fe,class_names=['no', 'yes'], filled = True) | |
graph = pydotplus.graph_from_dot_data(dot_data) | |
Image(graph.create_png()) | |
graph.write_png("dtree.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment