You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get 'KeyError: 'normal_e' at line 16. The error shows that I am trying to access a column named "normal_e", which is not present in the data.
I got it around the problem by implementing:
if 'normal_e' not in data[adj_matrix.value]:
data[adj_matrix.value]['normal_e'] = []
if 'normal_x' not in data[adj_matrix.value]:
data[adj_matrix.value]['normal_x'] = []
I applied this between under each of the if and elif statements, so it looked like:
def filter_features(data, gender=None):
"""
gender: either None, 'm' or 'w'. Use m/w when trying out gender-aware model, this will add an extra node_feature
the node feature will be 0 (m) and 1 (f). This is only relevent after loading both the M and W datasets (not implemented atm)
"""
edge_feature_idxs = [idx for idx, x in enumerate(edge_f_box.children) if x.value]
node_feature_idxs = [idx for idx, x in enumerate(node_f_box.children) if x.value]
node_features = [x.description for x in node_f_box.children if x.value]
# Check for empty edge features or node features.
if not any(edge_feature_idxs) and not any(node_feature_idxs):
print("\nCannot have zero edge features and zero node features.\n")
print("\nDefaulting to the previous configuration.")
else:
if not gender:
if 'normal_e' not in data[adj_matrix.value]:
data[adj_matrix.value]['normal_e'] = []
if 'normal_x' not in data[adj_matrix.value]:
data[adj_matrix.value]['normal_x'] = []
data[adj_matrix.value]['normal_e'] = [x[:, edge_feature_idxs] for x in data[adj_matrix.value]['normal_e']]
data[adj_matrix.value]['normal_x'] = [x[:, node_feature_idxs] for x in data[adj_matrix.value]['normal_x']]
elif gender == 'm':
if 'normal_e' not in data[adj_matrix.value]:
data[adj_matrix.value]['normal_e'] = []
if 'normal_x' not in data[adj_matrix.value]:
data[adj_matrix.value]['normal_x'] = []
data[adj_matrix.value]['normal_e'] = [x[:, edge_feature_idxs] for x in data[adj_matrix.value]['normal_e']]
data[adj_matrix.value]['normal_x'] = [np.append(
x[:, node_feature_idxs],
np.zeros(shape=(x.shape[0], 1)), axis=1
) for x in data[adj_matrix.value]['normal_x']]
elif gender == 'w':
if 'normal_e' not in data[adj_matrix.value]:
data[adj_matrix.value]['normal_e'] = []
if 'normal_x' not in data[adj_matrix.value]:
data[adj_matrix.value]['normal_x'] = []
data[adj_matrix.value]['normal_e'] = [x[:, edge_feature_idxs] for x in data[adj_matrix.value]['normal_e']]
data[adj_matrix.value]['normal_x'] = [np.append(
x[:, node_feature_idxs],
np.ones(shape=(x.shape[0], 1)), axis=1
) for x in data[adj_matrix.value]['normal_x']]
else:
raise NotImplementedError()
return data
data = filter_features(og_data.copy())
However, I'm aware there may be another fix using .loc. Just a thought.
The text was updated successfully, but these errors were encountered:
When running the cell:
2.6 Update dataset with selected features
I get 'KeyError: 'normal_e' at line 16. The error shows that I am trying to access a column named "normal_e", which is not present in the data.
I got it around the problem by implementing:
I applied this between under each of the if and elif statements, so it looked like:
However, I'm aware there may be another fix using .loc. Just a thought.
The text was updated successfully, but these errors were encountered: