-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_round_3 added to loading #129
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,4 +112,37 @@ def get_augmented_val_X_y(X, y, label): | |
|
||
|
||
|
||
|
||
def get_augmented_val_id(): | ||
'''get a dataset with augmented texts for the minority positive label | ||
Arguments: X, y - pandas series containing the validation data that needs to be augmented | ||
label - label that needs to be augmented | ||
sampling_strategy - float representing the proportion of positive vs negative labels in the augmented dataframe (range [>0.0; <=1.ß]) | ||
Return: augmented X, y''' | ||
|
||
label_range = ['label_sentimentnegative', 'label_inappropriate', 'label_discriminating', 'label_needsmoderation'] | ||
file_cached = "./cache/df_r3.csv" | ||
try: | ||
df_r3 = pd.read_csv(file_cached) | ||
|
||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is good practice to hande errrors explicitly: except FileError: |
||
df_r3 = loading.load_extended_posts(label=label) | ||
df_r3 = feature_engineering.add_column_ann_round(df_r3) | ||
df_r3 = feature_engineering.add_column_text(df_r3) | ||
df_r3 = df_r3.query('ann_round==3').copy() | ||
df_r3.to_csv(file_cached) | ||
|
||
df_r3 = feature_engineering.add_column_label_needsmoderation(df_r3) | ||
art_list = list(df_r3.id_article.unique()) | ||
|
||
label_range = ['label_sentimentnegative', 'label_inappropriate', 'label_discriminating', 'label_needsmoderation'] | ||
df_ann = pd.DataFrame(columns=df_r3.columns) | ||
|
||
id_list = [] | ||
for label in label_range: | ||
for i in art_list: | ||
df_ann = pd.concat((df_ann, | ||
df_r3.query(f'id_article=={i} and {label}==1').sample(1, | ||
random_state=42))) | ||
id_list.extend(list(df_ann.id_post)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small comment on efficiency: extending a list is not efficient. You could also use df_ann after both for-loops: id_list = list(df_ann.id_post.unique())
return id_list # or directly return the above |
||
|
||
return list(set(id_list)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are douplicating code from get_augmented_val_X_y. Best practise would be to use this function (get_augmented_val_id) in the X_y-function.