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: Return predictions for the input data
  
  Args:
      X (pd.DataFrame): A dataframe of shape (num_row, num_features) for model to predict
  
  Returns:
      Model's prediction: A numpy array of shape (num_row,)
  
  Raises:
      ValueError: if CPDs are empty
docstr_tok: ["Return","predictions","for","the","input","data","Args",":","X","(","pd.DataFrame",")",":","A","dataframe","of","shape","(","num_row",",","num_features",")","for","model","to","predict","Returns",":","Model","'s","prediction",":","A","numpy","array","of","shape","(","num_row",",",")","Raises",":","ValueError",":","if","CPDs","are","empty"]
code: def predict(self, X: pd.DataFrame) -> Union[pd.DataFrame, np.ndarray]:
      """
      Return predictions for the input data
  
      Args:
          X (pd.DataFrame): A dataframe of shape (num_row, num_features) for model to predict
  
      Returns:
          Model's prediction: A numpy array of shape (num_row,)
  
      Raises:
          ValueError: if CPDs are empty
  
      """
      if self.bn.cpds == {}:
          raise ValueError(
              "No CPDs found. The model has not been fitted"
          )
  
      X = self._discretise_features(X)
  
      if self.return_prob:
          pred = self.bn.predict_probability(X, self._target_name)
      else:
          pred = (
              self.bn.predict(X, self._target_name)
              .to_numpy()
              .reshape(-1)
          )
  
      return pred
  
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 5 for calling the BayesianNetworkClassifier obj's underlying member method code with example usage: obj.predict(X) and returns: pred