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: Build a Bayesian Network classifier from a set of training data.
  The method first discretises the feature using parameters in `discretiser_kwargs`
  and `discretiser_alg`. Next, it learns all the possible nodes that each feature
  can have. Finally, it learns the CPDs of the Bayesian Network.
  
  Args:
      X (pd.DataFrame): input training data
      y (pd.Series): categorical label for each row of X
  
  Returns:
      self
docstr_tok: ["Build","a","Bayesian","Network","classifier","from","a","set","of","training","data",".","The","method","first","discretises","the","feature","using","parameters","in","`","discretiser_kwargs","`","and","`","discretiser_alg","`",".","Next",",","it","learns","all","the","possible","nodes","that","each","feature","can","have",".","Finally",",","it","learns","the","CPDs","of","the","Bayesian","Network",".","Args",":","X","(","pd.DataFrame",")",":","input","training","data","y","(","pd.Series",")",":","categorical","label","for","each","row","of","X","Returns",":","self"]
code: def fit(
      self, X: pd.DataFrame, y: pd.Series
  ) -> "BayesianNetworkClassifier":
      """
      Build a Bayesian Network classifier from a set of training data.
      The method first discretises the feature using parameters in `discretiser_kwargs`
      and `discretiser_alg`. Next, it learns all the possible nodes that each feature
      can have. Finally, it learns the CPDs of the Bayesian Network.
  
      Args:
          X (pd.DataFrame): input training data
          y (pd.Series): categorical label for each row of X
  
      Returns:
          self
      """
      self._discretise_data = X.copy()
      self._discretise_data[y.name] = y
      self._target_name = y.name
      X = self._discretise_features(X)
  
      X[y.name] = y
      self.bn = self.bn.fit_node_states(X)
      self.bn = self.bn.fit_cpds(X, **self.probability_kwargs)
  
      return self
  
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 4 for calling the BayesianNetworkClassifier obj's underlying member method code with example usage: obj.fit(X, y) and returns: self