Professional Documents
Culture Documents
In [1]:
import pandas
df = pandas.read_csv("astronaut.csv")
print(df)
In [11]:
X = df[features]
y = df['Going to be an astronaut']
print("FEATURE COLUMNS")
print(X)
print("TARGET COLUMNS")
print(y)
FEATURE COLUMNS
Age Likes dogs Likes gravity
0 24 0 0
1 30 1 1
2 36 0 1
3 36 0 0
4 42 0 0
5 44 1 1
6 46 1 0
7 47 1 1
8 47 0 1
9 51 1 1
TARGET COLUMNS
0 0
1 1
2 1
3 0
4 0
5 1
6 0
7 1
8 0
9 1
Name: Going to be an astronaut, dtype: int64
In [17]:
import pandas
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
df = pandas.read_csv("astronaut.csv")
dtree = DecisionTreeClassifier()
dtree = dtree.fit(X.values, y)
print("PLOTTED DECISION TREE : ")
tree.plot_tree(dtree, feature_names=features)
Out[17]:
In [18]:
In [ ]: