update
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 193 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 193 KiB |
@@ -0,0 +1,12 @@
|
||||
1,0,1,1,
|
||||
0,1,0,0,
|
||||
1,0,1,1,
|
||||
1,1,1,1,
|
||||
0,0,1,0,
|
||||
1,0,0,0,
|
||||
0,1,1,0,
|
||||
0,0,1,0,
|
||||
1,0,0,0,
|
||||
1,1,1,1,
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
# Common imports
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.tree import export_graphviz
|
||||
from sklearn.preprocessing import StandardScaler, OneHotEncoder
|
||||
from sklearn.compose import ColumnTransformer
|
||||
from IPython.display import Image
|
||||
from pydot import graph_from_dot_data
|
||||
import os
|
||||
|
||||
# Where to save the figures and data files
|
||||
PROJECT_ROOT_DIR = "Results"
|
||||
FIGURE_ID = "Results/FigureFiles"
|
||||
DATA_ID = "DataFiles/"
|
||||
|
||||
if not os.path.exists(PROJECT_ROOT_DIR):
|
||||
os.mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
if not os.path.exists(FIGURE_ID):
|
||||
os.makedirs(FIGURE_ID)
|
||||
|
||||
if not os.path.exists(DATA_ID):
|
||||
os.makedirs(DATA_ID)
|
||||
|
||||
def image_path(fig_id):
|
||||
return os.path.join(FIGURE_ID, fig_id)
|
||||
|
||||
def data_path(dat_id):
|
||||
return os.path.join(DATA_ID, dat_id)
|
||||
|
||||
def save_fig(fig_id):
|
||||
plt.savefig(image_path(fig_id) + ".png", format='png')
|
||||
|
||||
infile = open(data_path("grades.csv"),'r')
|
||||
|
||||
# Read the experimental data with Pandas
|
||||
from IPython.display import display
|
||||
grades = pd.read_csv(infile, names = ('Trend','Sleep','Studied','Grade'))
|
||||
grades = pd.DataFrame(grades)
|
||||
display(grades)
|
||||
# Features and targets
|
||||
X = pd.to_numeric(grades.loc[:, grades.columns != 'Grade'].values)
|
||||
y = pd.to_numeric(grades.loc[:, grades.columns == 'Grade'].values)
|
||||
print(X)
|
||||
# Create the encoder.
|
||||
encoder = OneHotEncoder(handle_unknown="ignore")
|
||||
# Assume for simplicity all features are categorical.
|
||||
encoder.fit(X)
|
||||
# Apply the encoder.
|
||||
X = encoder.transform(X)
|
||||
# Then do a Classification tree
|
||||
tree_clf = DecisionTreeClassifier(max_depth=2)
|
||||
tree_clf.fit(X, y)
|
||||
print("Train set accuracy with Decision Tree: {:.2f}".format(tree_clf.score(X,y)))
|
||||
#transfer to a decision tree graph
|
||||
export_graphviz(
|
||||
tree_clf,
|
||||
out_file="DataFiles/grade.dot",
|
||||
rounded=True,
|
||||
filled=True
|
||||
)
|
||||
cmd = 'dot -Tpng DataFiles/grade.dot -o DataFiles/grades.png'
|
||||
os.system(cmd)
|
||||
|
||||
|
||||
#data_pandas = pd.DataFrame(data,index=['Frodo','Bilbo','Aragorn','Sam'])
|
||||
#df.columns = ['First', 'Second', 'Third', 'Fourth', 'Fifth']
|
||||