我正在调用这个方法build_feature_category
obt=ObliviousTree(data,"hello",True)#data is pandas.DataFrame
obt.load_tree()
obt.build_feature_category()
但它给出了这个错误,我认为这与它们在创建之前使用实例变量有关但我不太确定我在哪里做错了: 这是我在该类上面调用上述方法后得到的错误
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)
答案 0 :(得分:2)
np.unique
是一种方法,但您将其称为dict。它应该是:
... = np.unique(self.data[feature_name])