In [50]:
import pandas as pd
%matplotlib inline
from sklearn import datasets
from sklearn import tree
import matplotlib.pyplot as plt
from random import shuffle
In [157]:
def lets_shake(x,y):
zipped = zip(x,y) # Let's bind the x and the y together before shakin'.
zipped_list = list(zipped)
shuffle(zipped_list)
x, y = zip(*zipped_list)
return x, y
In [222]:
def the_splitter(x,y,folds):
divider = int(len(x)/folds)
group_dict = {}
for i in range(0,folds):
temp_list = list()
for j in range(i*divider,(i+1)*divider):
temp_list.append((x[j], y[j]))
group_dict['group' + str(i)] = temp_list
return group_dict
# This function still neglect a small rest of the values.
In [246]:
def the_test(groups,folds):
dt = tree.DecisionTreeClassifier()
for group in groups:
dt = dt.fit(x,y)
#dt.predict()
#score()
In [231]:
x = [[1, 1], [2, 2], [3, 3], [4, 4], [5,5], [6,6], [7,7], [8,8], [9,9], [10,10]]
y = [0,2,1,1,0,1,2,1,1,0]
In [232]:
x,y = lets_shake(x,y)
groups = the_splitter(x,y,5)
In [236]:
groups
Out[236]:
In [ ]:
In [ ]:
In [ ]: