Given the following code:
class DTC:
def __init__(self):
self.__root = None
def unique(self,Y):
d = {}
for i in Y:
if i not in d:
d[i]=1
else:
d[i]+=1
return d
def ent(self,Y):
freq = self.__count_unique(Y)
ent_ = 0
total = len(Y)
for i in freq:
p = freq[i]/total
entropy_ += (-p)*math.log2(p)
return ent_
The above will run if it is place in a single cell in Jupyter Notebook. However, how can I make the class code work if I want it to be split into multiple cells like this:
Cell 1
class DTC:
def __init__(self):
self.__root = None
Cell 2
def unique(self,Y):
d = {}
for i in Y:
if i not in d:
d[i]=1
else:
d[i]+=1
return d
Cell 3
def ent(self,Y):
freq = self.__unique(Y)
ent_ = 0
total = len(Y)
for i in freq:
p = freq[i]/total
ent_ += (-p)*math.log2(p)
return ent_