Reputation: 2322
i am calling the method build_feature_category
like this
obt=ObliviousTree(data,"hello",True)#data is pandas.DataFrame
obt.load_tree()
obt.build_feature_category()
but it is giving this error,i think it has to do with using instance variable before they get created but i am not quite sure where i am doing it wrong: this is the error i am getting after calling those method above on that class
label session week hour category item dwell
-1 1 0 10 0 214536502 0.000
-1 1 0 10 0 214536500 180.591
-1 1 0 10 0 214536506 37.130 -1 1 0 10 0 214577561 133.308
-1 2 0 13 0 214662742 0.000
-1 2 0 13 0 214662742 41.759
-1 2 0 13 0 214825110 78.073
-1 2 0 13 0 214757390 73.264
-1 2 0 14 0 214757407 47.537
-1 2 0 14 0 214551617 118.642
['label', 'session', 'week', 'hour', 'category', 'item', 'dwell']
Traceback (most recent call last):
File "dataloader.py", line 39, in <module>
obt.build_feature_category()
File "/sdfs/challenge/odg/ObliviousTree.py", line 24, in build_feature_category
self.feature_name_values[feature_name]=np.unique[self.data[feature_name]]
TypeError: 'function' object is not subscriptable
import numpy as np
class ObliviousTree:
'This is an implementation of Oblvious Tree'
def __init__(self,data=[],func="C.45",autoload=False):
self.data=data
self.split_funct=func
self.autoload=autoload
self.feature_names=self.data.columns.tolist()
self.feature_name_values={}
def load_tree(self):
if not self.autoload:
print("skipped autoloading")
else:
print(self.data)
print(self.feature_names)
def build_feature_category(self):
for feature_name in self.feature_names:
self.feature_name_values[feature_name]=np.unique[self.data[feature_name]]
print(self.feature_name_values)
Upvotes: 0
Views: 1379
Reputation: 599610
np.unique
is a method, but you are calling it as if it was a dict. It should be:
... = np.unique(self.data[feature_name])
Upvotes: 2