# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Causal Learning on Breast Cancer Dataset

# +
import os
import sys
sys.path.append(os.path.abspath(os.path.join('..')))

import warnings
warnings.filterwarnings('ignore')
# -

## Scientific Modules
from sklearn.model_selection import train_test_split

# +
import warnings
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

from causalnex.discretiser import Discretiser
from causalnex.structure import DAGRegressor
from causalnex.inference import InferenceEngine
from causalnex.network import BayesianNetwork
from causalnex.network.sklearn import BayesianNetworkClassifier
from causalnex.structure.notears import from_pandas
from causalnex.utils.network_utils import get_markov_blanket


from causalnex.structure.notears import from_pandas, from_pandas_lasso
from causalnex.discretiser.discretiser_strategy import ( DecisionTreeSupervisedDiscretiserMethod )

from sklearn.model_selection import KFold
from sklearn.model_selection import train_test_split
from sklearn.metrics import recall_score, f1_score, accuracy_score

from causalnex.plots import plot_structure, NODE_STYLE, EDGE_STYLE
from IPython.display import Markdown, display, Image, display_html
# -

# Pandas configration
import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)

# +
# Custom Modules

from myscripts import file
from myscripts import utils
# -

# ### Read Dataset

file_name = '../data/clean_breast_cancer.csv'
data = file.read_csv(file_name)

data.head()

# ### change label of diagnosis column
# This will help us prepare our dataset for Machine learning

data['diagnosis'] = data['diagnosis'].apply(utils.labeler)

data.head()

# ### Train Test Split

# +
# X = data.drop(['id', 'diagnosis'], axis=1)
# y = data['diagnosis']

# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
train, test = train_test_split(data, test_size=0.3)
train.head()
# -

# ### Create a causal graph using all training data and get the insights (this will be considered the ground truth)

# +
# # ! pip install pygraphviz

# +

sm = from_pandas(data, w_threshold=0.8)
viz = plot_structure(
    sm,
    graph_attributes={"scale": "2.0", 'size':2.5},
    all_node_attributes=NODE_STYLE.WEAK,
    all_edge_attributes=EDGE_STYLE.WEAK)
Image(viz.draw(format='png'))
# -



# ### Create new causal graphs using increasing fractions of the data and compare with the ground truth graph
#     a. The comparison can be done with a Jaccard Similarity Index, measuring
#         the intersection and union of the graph edges





# ### After reaching a stable causal graph, select only variables that point directly to the target variable
#







# ### Train one model using all variables and another using only the variables selected by the graph





# ### Measure how much each of the models overfit the hold-out set created in step 1.



StarcoderdataJupyterScriptsDedupFiltered