<jupyter_start><jupyter_text>Machine Learning (One vs All)  Modules and functions Import all the modules:<jupyter_code>import pandas as pd

from xgboost import XGBClassifier

import matplotlib.pyplot as plt
%matplotlib inline

plt.style.use("ggplot")

from notebooks import *<jupyter_output><empty_output><jupyter_text>Loading<jupyter_code>honey_badger_labels = load_dictionary("honey_badger_labels.pickle")
df_file_path = "dataset-filtered.csv"
df = pd.read_csv(df_file_path, low_memory=False)
print_dimensions(df)<jupyter_output>The dataset has 158863 rows and 434 columns<jupyter_text>Prepare data<jupyter_code>addresses, X, y_binary, y_multi, scaler, feature_names = extract_experiment_data(df)
for feature_name in feature_names:
    print(feature_name)<jupyter_output>contract_compiler_runs
contract_num_source_code_lines
internal_transaction_count
normal_transaction_block_span
normal_transaction_count
normal_transaction_block_delta_mean
normal_transaction_block_delta_std
normal_transaction_count_per_block_mean
normal_transaction_count_per_block_std
normal_transaction_gas_mean
normal_transaction_gas_std
normal_transaction_gas_used_mean
normal_transaction_gas_used_std
normal_transaction_time_delta_mean
normal_transaction_time_delta_std
normal_transaction_value_mean
normal_transaction_value_std
contract_has_library
has_internal_transactions
normal_transaction_before_creation_ratio
normal_transaction_block_ratio
normal_transaction_from_other_ratio
normal_transaction_other_sender_ratio
contract_compiler_minor_version_0
contract_compiler_minor_version_1
contract_compiler_minor_version_2
contract_compiler_minor_version_3
contract_compiler_patch_0
contract_compiler_patch_1
contract_compiler_patch_2
contract_compiler_patch_3
contract_compiler_patch_4
contrac[...]<jupyter_text>Classification<jupyter_code>xgb_scale_pos_weight = compute_scale_pos_weight(y_binary)
def create_xgb_model():
    return XGBClassifier(n_jobs=10,
                         scale_pos_weight=xgb_scale_pos_weight,
                         n_estimators=25,
                         max_depth=3)
num_labels = len(honey_badger_labels["index_to_name"])

for label_id, label_value in enumerate(honey_badger_labels["index_to_name"][1:], start=1):
    print("Label {:d}/{:d} = {}".format(label_id, num_labels, label_value))

    train_index = y_multi != label_id
    test_index = y_multi == label_id
    
    xgb_model = create_xgb_model()
    xgb_model.fit(X[train_index], y_binary[train_index])
    
    train_metrics = compute_metrics(y_binary[train_index], xgb_model.predict(X[train_index]))
    print_metrics("train", train_metrics)
    
    test_pred = xgb_model.predict(X[test_index])
    test_size = test_pred.shape[0]
    test_tp = test_pred.sum()
    test_fp = test_size - test_tp
    test_acc = test_tp / test_size
    print("test  Recall {:.03f} FN {:d} TP {:d}".format(test_acc, test_fp, test_tp))
    print()<jupyter_output>Label 1/9 = Balance Disorder
train ROC AUC 0.981 TN  156456 FP  2112 FN     7 TP   268
test  Recall 0.850 FN 3 TP 17

Label 2/9 = Hidden State Update
train ROC AUC 0.984 TN  157575 FP   993 FN     4 TP   156
test  Recall 0.911 FN 12 TP 123

Label 3/9 = Hidden Transfer
train ROC AUC 0.982 TN  156654 FP  1914 FN     7 TP   275
test  Recall 0.923 FN 1 TP 12

Label 4/9 = Inheritance Disorder
train ROC AUC 0.985 TN  156804 FP  1764 FN     5 TP   247
test  Recall 0.884 FN 5 TP 38

Label 5/9 = Skip Empty String Literal
train ROC AUC 0.987 TN  156206 FP  2362 FN     3 TP   282
test  Recall 0.900 FN 1 TP 9

Label 6/9 = Straw Man Contract
train ROC AUC 0.984 TN  156479 FP  2089 FN     5 TP   259
test  Recall 0.903 FN 3 TP 28

Label 7/9 = Type Deduction Overflow
train ROC AUC 0.984 TN  156607 FP  1961 FN     6 TP   285
test  Recall 1.000 FN 0 TP 4

Label 8/9 = Uninitialised Struct
train ROC AUC 0.988 TN  156687 FP  1881 FN     3 TP   253
test  Recall 0.949 FN 2 TP 37
{'fraction_non_alphanumeric': 0.059912573926459246, 'fraction_numerical': 0.06248392903059913, 'mean_word_length': 4.993836671802773, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '229117', 'license': 'MIT', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1323, 'n_words': 334, 'path': 'paper_experiments/4 - Machine Learning One vs All.ipynb', 'repo_name': 'betaswap/honeypot-detection', 'size': '3889'}