def compute_accuracy_with_drift()

in src/drift_detector.py [0:0]


def compute_accuracy_with_drift(test_df, infer_df, target_label):
    """Compute accuracy loss due to model drift."""
    test_df = utils.auto_impute_df(test_df)
    
    x_pos = test_df[test_df[target_label] == 1].drop(target_label, axis=1)

    # Create Isolation Forest to create one-class classifier to identify positive labels
    isof = IsolationForest(n_estimators=100, n_jobs=-1, contamination=0, verbose=1, max_features=x_pos.shape[1],
                           max_samples=x_pos.shape[0], bootstrap=False, random_state=123)

    isof.fit(x_pos)
    scores = isof.score_samples(x_pos)
    pos_score_mean = np.mean(scores)

    # Compute anomaly scores of inference data and compare with original scores computed on positive samples of test
    # dataset
    infer_df = utils.auto_impute_df(infer_df)
    pred_score_mean = np.mean(isof.score_samples(infer_df))

    accuracy = 100 - abs((pred_score_mean - pos_score_mean) / pos_score_mean) * 100

    return accuracy