I keep getting the following error: AttributeError: 'tuple' object has no attribute 'size'. The split function also added
import numpy as np
def split(array):
N = {}
uniqe_array = np.unique(array)
for i in uniqe_array:
N[i] = np.where(array==i)
return N
def information_gain(x_array, y_array):
parent_entropy = entropy(x_array)
split_dict = split(y_array)
for val in split_dict.values():
freq = val.size / x_array.size
child_entropy = entropy([x_array[i] for i in val])
parent_entropy -= child_entropy* freq
return parent_entropy
x = np.array([0, 1, 0, 1, 0, 1])
y = np.array([0, 1, 0, 1, 1, 1])
print(round(information_gain(x, y), 4))
x = np.array([0, 0, 1, 1, 2, 2])
y = np.array([0, 1, 0, 1, 1, 1])
print(round(information_gain(x, y), 4))