<jupyter_start><jupyter_text>Causal direction: 1 means that X -> Y; and 0 the other way around.<jupyter_code>x, y, target, _ = data[idx]
print('Causal direction:', target)
print('nb samples:', len(x))
viz.pretty_scatter(x, y)
from cdt.causality.pairwise import ANM
from cdt.data import load_dataset
data, labels = load_dataset('tuebingen')
obj = ANM()
output = obj.predict(data)
from sklearn.metrics import roc_curve, roc_auc_score, precision_recall_curve, auc
y_true = labels.values
pred = output
precision, recall, _ = precision_recall_curve(y_true=y_true, probas_pred=pred, pos_label=1)
auc_score = auc(recall, precision)
auc_score
acc = 0
for i in range(len(y_true)):
    corr = int(pred[i] > 0) == y_true[i]
    acc += corr
acc / len(pred)
from cdt.metrics import precision_recall
aupr, curve = precision_recall(np.asarray(y_true), np.asarray(pred))
aupr

plt.plot(recall, precision, marker='.', label='Logistic')
plt.xlabel('recall')
plt.ylabel('precision')
labels
from cdt.causality.pairwise import IGCI
igci = IGCI()
output_igci = igci.predict(data)
acc = 0
for i in range(len(y_true)):
    corr = int(output_igci[i] > 0) == y_true[i]
    acc += corr
acc / len(output_igci)
data
import pandas as pd
x = [1, 2, 3]
y = [4, 5, 6]
def to_df(x, y):
    df = pd.DataFrame({'A':[np.asarray(x)]})
    df['B'] = [np.asarray(y)]
    return df
df = to_df(x, y)
output_igci = igci.predict(df)
output_igci
# 'CE-Tueb', 'CE-Gauss', 'CE-Cha', 'CE-Multi', 'CE-Net'
data = dataset.load_dataset('CE-Tueb')
cdt_method=True
acc = 0
idx = 0
for x, y, target, _ in data:
    
    if cdt_method == True:
        df = to_df(x, y)
        score = igci.predict(df)
        pred = score[0][0] > 0
        
        acc += pred == target
        print(idx)
        idx += 1
acc / len(data)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15016685205784205, 'fraction_numerical': 0.010567296996662959, 'mean_word_length': 4.1253561253561255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '653947', 'license': 'MIT', 'n_tokens_mistral': 744, 'n_tokens_neox': 711, 'n_words': 176, 'path': 'benchmark/test CDT.ipynb', 'repo_name': 'Nacho114/bivariate-causal-inference', 'size': '1798'}