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: Args:
      list_of_edges (list): Edge list to construct graph
      - if True: return pandas dataframe with predicted probability for each state
      - if False: return a 1-D prediction array
      discretiser_alg (dict): Specify a supervised algorithm to discretise
      each feature in the data. Available options for the dictionary values
      are ['unsupervised', 'tree', 'mdlp']
      - if 'unsupervised': discretise the data using unsupervised method
      - if 'tree': discretise the data using decision tree method
      - if 'mdlp': discretise the data using MDLP method
      discretiser_kwargs (dict): Keyword arguments for discretisation methods.
      Only applicable if discretiser_alg is not None.
      probability_kwargs (dict): keyword arguments for the probability model
      return_prob (bool): choose to return predictions or probability
  
  Raises:
      KeyError: If an incorrect argument is passed
      ValueError: If the keys in discretiser_alg and discretiser_kwargs differ
docstr_tok: ["Args",":","list_of_edges","(","list",")",":","Edge","list","to","construct","graph","-","if","True",":","return","pandas","dataframe","with","predicted","probability","for","each","state","-","if","False",":","return","a","1-D","prediction","array","discretiser_alg","(","dict",")",":","Specify","a","supervised","algorithm","to","discretise","each","feature","in","the","data",".","Available","options","for","the","dictionary","values","are","[","'unsupervised","'",",","'tree","'",",","'mdlp","'","]","-","if","'unsupervised","'",":","discretise","the","data","using","unsupervised","method","-","if","'tree","'",":","discretise","the","data","using","decision","tree","method","-","if","'mdlp","'",":","discretise","the","data","using","MDLP","method","discretiser_kwargs","(","dict",")",":","Keyword","arguments","for","discretisation","methods",".","Only","applicable","if","discretiser_alg","is","not","None",".","probability_kwargs","(","dict",")",":","keyword","arguments","for","the","probability","model","return_prob","(","bool",")",":","choose","to","return","predictions","or","probability","Raises",":","KeyError",":","If","an","incorrect","argument","is","passed","ValueError",":","If","the","keys","in","discretiser_alg","and","discretiser_kwargs","differ"]
code: def __init__(
      self,
      list_of_edges: List[Tuple[str]],
      discretiser_alg: Optional[Dict[str, str]] = None,
      discretiser_kwargs: Optional[Dict[str, Dict[str, Any]]] = None,
      probability_kwargs: Dict[str, Dict[str, Any]] = None,
      return_prob: bool = False,
  ):
      """
      Args:
          list_of_edges (list): Edge list to construct graph
          - if True: return pandas dataframe with predicted probability for each state
          - if False: return a 1-D prediction array
          discretiser_alg (dict): Specify a supervised algorithm to discretise
          each feature in the data. Available options for the dictionary values
          are ['unsupervised', 'tree', 'mdlp']
          - if 'unsupervised': discretise the data using unsupervised method
          - if 'tree': discretise the data using decision tree method
          - if 'mdlp': discretise the data using MDLP method
          discretiser_kwargs (dict): Keyword arguments for discretisation methods.
          Only applicable if discretiser_alg is not None.
          probability_kwargs (dict): keyword arguments for the probability model
          return_prob (bool): choose to return predictions or probability
  
      Raises:
          KeyError: If an incorrect argument is passed
          ValueError: If the keys in discretiser_alg and discretiser_kwargs differ
      """
  
      probability_kwargs = probability_kwargs or {
          "method": "BayesianEstimator",
          "bayes_prior": "K2",
      }
  
      if discretiser_alg is None:
          logging.info(
              "No discretiser algorithm was given "
              "The training data will not be discretised"
          )
          discretiser_alg = {}
  
      discretiser_kwargs = discretiser_kwargs or {}
  
      self._validate_discretiser(discretiser_alg, discretiser_kwargs)
  
      self.list_of_edges = list_of_edges
      self.structure = StructureModel(self.list_of_edges)
      self.bn = BayesianNetwork(self.structure)
      self.return_prob = return_prob
      self.probability_kwargs = probability_kwargs
      self.discretiser_kwargs = discretiser_kwargs
      self.discretiser_alg = discretiser_alg
      self._target_name = None
      self._discretise_data = None
  
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 1 to create a new BayesianNetworkClassifier object from inherited base classes: BaseEstimator, ClassifierMixin with example: obj = BayesianNetworkClassifier(list_of_edges, discretiser_alg, discretiser_kwargs, probability_kwargs, return_prob)