class_docstr: A class that supports discretising features and probability fitting with scikit-learn syntax
  
  Example:
  ::
      # Dataset is from https://archive.ics.uci.edu/ml/datasets/student+performance
      >>> import pandas as pd
      >>> import numpy as np
      >>> from sklearn.preprocessing import LabelEncoder
      >>> from causalnex.discretiser import Discretiser
      >>> from causalnex.network.sklearn import BayesianNetworkClassifier
      >>> from sklearn.model_selection import train_test_split
      >>> data = pd.read_csv('student-por.csv', delimiter=';')
      >>> drop_col = ['school','sex','age','Mjob', 'Fjob','reason','guardian']
      >>> data = data.drop(columns=drop_col)
      >>> non_numeric_columns = list(data.select_dtypes(exclude=[np.number]).columns)
      >>> le = LabelEncoder()
      >>> for col in non_numeric_columns:
      >>>     data[col] = le.fit_transform(data[col])
      >>> data["G3"] = Discretiser(method="fixed",
                    numeric_split_points=[10]).transform(data["G3"].values)
      >>> label = data["G3"]
      >>> data.drop(['G3'], axis=1, inplace=True)
      >>> X_train, X_test, y_train, y_test = train_test_split(
                      data, label, test_size=0.1, random_state=7)
      >>> edge_list = [('address', 'absences'),
                       ('Pstatus', 'famrel'),
                       ('Pstatus', 'absences'),
                       ('studytime', 'G1'),
                       ('G1', 'G2'),
                       ('failures', 'absences'),
                       ('failures', 'G1'),
                       ('schoolsup', 'G1'),
                       ('paid', 'absences'),
                       ('higher', 'famrel'),
                       ('higher', 'G1'),
                       ('internet', 'absences'),
                       ('G2', 'G3')]
      >>> discretiser_param = {
              'absences': {'method':"fixed",
                           'numeric_split_points':[1, 10]
                          },
               'G1': {'method':"fixed",
                      'numeric_split_points':[10]
                     },
               'G2': {'method':"fixed",
                      'numeric_split_points':[10]
                     }
              }
      >>> discretiser_alg = {'absences': 'unsupervised',
                            'G1': 'unsupervised',
                            'G2': 'unsupervised'
                           }
      >>> bayesian_param = {'method':"BayesianEstimator", 'bayes_prior':"K2"}
      >>> clf = BayesianNetworkClassifier(edge_list, discretiser_alg, discretiser_param, bayesian_param)
      >>> clf.fit(X_train, y_train)
      >>> clf.predict(X_test)
      array([1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
             1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1,
             1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0])
class_docstr_tok: ["A","class","that","supports","discretising","features","and","probability","fitting","with","scikit-learn","syntax","Example",":",":",":","#","Dataset","is","from","https",":","\/\/archive.ics.uci.edu\/ml\/datasets\/student+performance",">",">",">","import","pandas","as","pd",">",">",">","import","numpy","as","np",">",">",">","from","sklearn.preprocessing","import","LabelEncoder",">",">",">","from","causalnex.discretiser","import","Discretiser",">",">",">","from","causalnex.network.sklearn","import","BayesianNetworkClassifier",">",">",">","from","sklearn.model_selection","import","train_test_split",">",">",">","data","=","pd.read_csv","(","'student-por.csv","'",",","delimiter=","'",";","'",")",">",">",">","drop_col","=","[","'school","'",",","'sex","'",",","'age","'",",","'Mjob","'",",","'Fjob","'",",","'reason","'",",","'guardian","'","]",">",">",">","data","=","data.drop","(","columns=drop_col",")",">",">",">","non_numeric_columns","=","list","(","data.select_dtypes","(","exclude=","[","np.number","]",")",".columns",")",">",">",">","le","=","LabelEncoder","(",")",">",">",">","for","col","in","non_numeric_columns",":",">",">",">","data","[","col","]","=","le.fit_transform","(","data","[","col","]",")",">",">",">","data","[","``","G3","''","]","=","Discretiser","(","method=","''","fixed","''",",","numeric_split_points=","[","10","]",")",".transform","(","data","[","``","G3","''","]",".values",")",">",">",">","label","=","data","[","``","G3","''","]",">",">",">","data.drop","(","[","'G3","'","]",",","axis=1",",","inplace=True",")",">",">",">","X_train",",","X_test",",","y_train",",","y_test","=","train_test_split","(","data",",","label",",","test_size=0.1",",","random_state=7",")",">",">",">","edge_list","=","[","(","'address","'",",","'absences","'",")",",","(","'Pstatus","'",",","'famrel","'",")",",","(","'Pstatus","'",",","'absences","'",")",",","(","'studytime","'",",","'G1","'",")",",","(","'G1","'",",","'G2","'",")",",","(","'failures","'",",","'absences","'",")",",","(","'failures","'",",","'G1","'",")",",","(","'schoolsup","'",",","'G1","'",")",",","(","'paid","'",",","'absences","'",")",",","(","'higher","'",",","'famrel","'",")",",","(","'higher","'",",","'G1","'",")",",","(","'internet","'",",","'absences","'",")",",","(","'G2","'",",","'G3","'",")","]",">",">",">","discretiser_param","=","{","'absences","'",":","{","'method","'",":","''","fixed","''",",","'numeric_split_points","'",":","[","1",",","10","]","}",",","'G1","'",":","{","'method","'",":","''","fixed","''",",","'numeric_split_points","'",":","[","10","]","}",",","'G2","'",":","{","'method","'",":","''","fixed","''",",","'numeric_split_points","'",":","[","10","]","}","}",">",">",">","discretiser_alg","=","{","'absences","'",":","'unsupervised","'",",","'G1","'",":","'unsupervised","'",",","'G2","'",":","'unsupervised'","}",">",">",">","bayesian_param","=","{","'method","'",":","''","BayesianEstimator","''",",","'bayes_prior","'",":","''","K2","''","}",">",">",">","clf","=","BayesianNetworkClassifier","(","edge_list",",","discretiser_alg",",","discretiser_param",",","bayesian_param",")",">",">",">","clf.fit","(","X_train",",","y_train",")",">",">",">","clf.predict","(","X_test",")","array","(","[","1",",","1",",","1",",","1",",","1",",","0",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","0",",","1",",","1",",","1",",","0",",","1",",","1",",","1",",","1",",","1",",","1",",","0",",","0",",","1",",","1",",","0",",","1",",","0",",","1",",","0",",","1",",","0",",","1",",","1",",","1",",","1",",","1",",","0",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","0",",","1",",","1",",","1",",","1",",","0",",","0",",","1",",","1",",","0","]",")"]
docstr: Helper method to discretise input data using parameters in
  `discretiser_kwargs` and `discretiser_alg`.
  The splitting thresholds are extracted from the training data
  
  Args:
      X (pd.DataFrame): a dataframe to be discretised
  
  Returns:
      a discretised version of the input dataframe
docstr_tok: ["Helper","method","to","discretise","input","data","using","parameters","in","`","discretiser_kwargs","`","and","`","discretiser_alg","`",".","The","splitting","thresholds","are","extracted","from","the","training","data","Args",":","X","(","pd.DataFrame",")",":","a","dataframe","to","be","discretised","Returns",":","a","discretised","version","of","the","input","dataframe"]
code: def _discretise_features(self, X: pd.DataFrame) -> pd.DataFrame:
      """
      Helper method to discretise input data using parameters in
      `discretiser_kwargs` and `discretiser_alg`.
      The splitting thresholds are extracted from the training data
  
      Args:
          X (pd.DataFrame): a dataframe to be discretised
  
      Returns:
          a discretised version of the input dataframe
      """
  
      X = X.copy()
  
      for col in self.discretiser_alg.keys():
          if self.discretiser_alg[col] == "unsupervised":
              if self.discretiser_kwargs[col]["method"] == "fixed":
                  X[col] = Discretiser(
                      **self.discretiser_kwargs[col]
                  ).transform(X[col].values)
              else:
                  discretiser = Discretiser(
                      **self.discretiser_kwargs[col]
                  ).fit(self._discretise_data[col].values)
                  X[col] = discretiser.transform(X[col].values)
  
          else:
              if self.discretiser_alg[col] == "tree":
                  discretiser = DecisionTreeSupervisedDiscretiserMethod(
                      mode="single",
                      tree_params=self.discretiser_kwargs[col],
                  )
  
              elif self.discretiser_alg[col] == "mdlp":
                  discretiser = MDLPSupervisedDiscretiserMethod(
                      self.discretiser_kwargs[col]
                  )
  
              discretiser.fit(
                  dataframe=self._discretise_data,
                  feat_names=[col],
                  target=self._target_name,
                  target_continuous=False,
              )
  
              X[col] = discretiser.transform(X[[col]])
  
      return X
  
file_path: causalnex/causalnex/network/sklearn/models.py
imports: import logging
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import pandas
  from sklearn.base import BaseEstimator, ClassifierMixin
  from causalnex.discretiser import Discretiser
  from causalnex.discretiser.discretiser_strategy import DecisionTreeSupervisedDiscretiserMethod, MDLPSupervisedDiscretiserMethod
  from causalnex.network import BayesianNetwork
  from causalnex.structure import StructureModel
label_desc: Use image node_id 3 for calling the BayesianNetworkClassifier obj's underlying member method code with example usage: obj._discretise_features(X) and returns: X