有没有一种方法可以基于布尔限制对H20帧进行切片?我做了一个函数来收集Trues和False的数组。我的目标是基于这个布尔数组对H2O帧进行切片。
用于复制目的:
#Creation of Dataset
X,y = make_classification(n_samples=5000, n_features=15,n_informative=15, n_redundant=0, n_repeated=0, n_classes=4
,n_clusters_per_class=2,class_sep=3,flip_y=0.1,weights=[0.4,0.20,0.10,0.05], shuffle=True,random_state=1234)
dataset_x = pd.DataFrame({'var1': X[:, 0], 'var2': X[:, 1],'var3': X[:, 2]})
dataset_x['var2'] = dataset_x['var3'].round(0)
dataset_x['var3'] = dataset_x['var3']*(-1)
dataset_x['var4'] =np.where(dataset_x['var1']<=0, 0, 1)
conditions = [(dataset_x['var2'] <= 0) & (dataset_x['var4'] == 0)
,(dataset_x['var2'] <=0) & (dataset_x['var4'] == 1)
,(dataset_x['var2'] >=0) & (dataset_x['var4'] == 0)
,(dataset_x['var2'] >=0) & (dataset_x['var4'] == 1)]
choices = [0, 1, 2, 3]
dataset_x['var5'] = np.select(conditions, choices, default=0)
dataset_x['var6'] = dataset_x['var3'].abs().round(0)
mean_var1 = dataset_x['var3'].mean()
len_var1 = len(dataset_x['var3'])
dataset_x['var7'] =(mean_var1*(2.718)**((mean_var1)*(dataset_x['var1'].round(0))*-1))
dataset_x['var8'] =dataset_x['var1'].round(0)
dataset_x['var8'] =abs(dataset_x['var1'].round(0))*2
dataset_y = pd.DataFrame({'target': y})
simulated_irregular_dataset = pd.concat([dataset_x,dataset_y], axis=1)
定义布尔切片器:
def boolean_slicer(size,num_feat):
array_slicer = []
for i in range(size):
slicer = np.ones(num_feat,dtype=np.bool)
slicer[:int(0.5*num_feat)]=False
np.random.shuffle(slicer)
array_slicer.append(slicer)
return array_slicer
将布尔限制应用于H2O帧:
h2o.init(min_mem_size_GB=8)
#Transform data into a H2O Frame
H20_df = h2o.H2OFrame(X_train)
print(H20_df)
for i in list_of_Boolean:
print (i)
print(H20_df[:,i.tolist()])
收到错误:
H2OResponseError: Server error water.rapids.Rapids.IllegalASTException:
Error: java.lang.NumberFormatException: For input string: "False"
Request: POST /99/Rapids
data: {'ast': '(tmp= py_16_sid_9474 (cols_py Key_Frame__upload_8abf91f6bc0ddcd442f8fa9b6f8b4822.hex [False True True True True True False True]))', 'session_id': '_sid_9474'}
我只需要将布尔值转换为int。
X,y = make_classification(n_samples=5000, n_features=15,n_informative=15, n_redundant=0, n_repeated=0, n_classes=4
,n_clusters_per_class=2,class_sep=3,flip_y=0.1,weights=[0.4,0.20,0.10,0.05], shuffle=True,random_state=1234)
dataset_x = pd.DataFrame({'var1': X[:, 0], 'var2': X[:, 1],'var3': X[:, 2]})
dataset_x['var2'] = dataset_x['var3'].round(0)
dataset_x['var3'] = dataset_x['var3']*(-1)
dataset_x['var4'] =np.where(dataset_x['var1']<=0, 0, 1)
conditions = [(dataset_x['var2'] <= 0) & (dataset_x['var4'] == 0)
,(dataset_x['var2'] <=0) & (dataset_x['var4'] == 1)
,(dataset_x['var2'] >=0) & (dataset_x['var4'] == 0)
,(dataset_x['var2'] >=0) & (dataset_x['var4'] == 1)]
choices = [0, 1, 2, 3]
dataset_x['var5'] = np.select(conditions, choices, default=0)
dataset_x['var6'] = dataset_x['var3'].abs().round(0)
mean_var1 = dataset_x['var3'].mean()
len_var1 = len(dataset_x['var3'])
dataset_x['var7'] =(mean_var1*(2.718)**((mean_var1)*(dataset_x['var1'].round(0))*-1))
dataset_x['var8'] =dataset_x['var1'].round(0)
dataset_x['var8'] =abs(dataset_x['var1'].round(0))*2
dataset_y = pd.DataFrame({'target': y})
simulated_irregular_dataset = pd.concat([dataset_x,dataset_y], axis=1)
def boolean_slicer(size,num_feat):
array_slicer = []
for i in range(size):
slicer = np.ones(num_feat,dtype=np.bool)
slicer[:int(0.3*num_feat)]=False
np.random.shuffle(slicer)
array_slicer.append(slicer)
return array_slicer
list_of_Boolean = boolean_slicer(20,8)
for i in popo:
print(i.tolist())
h2o.init(min_mem_size_GB=8)
#Transform data into a H2O Frame
H20_df = h2o.H2OFrame(X_train)
print(H20_df)
for i in list_of_Boolean:
print (i)
i = 1*i
i = i.astype(int)
print(H20_df[:,i.tolist()])