class_docstr: Base class for all sklearn wrappers of the StructureModel.
  Implements the sklearn .fit and .predict interface.
class_docstr_tok: ["Base","class","for","all","sklearn","wrappers","of","the","StructureModel",".","Implements","the","sklearn",".fit","and",".predict","interface","."]
docstr: Fits the sm model using the concat of X and y.
docstr_tok: ["Fits","the","sm","model","using","the","concat","of","X","and","y","."]
code: def fit(
      self,
      X: Union[pd.DataFrame, np.ndarray],
      y: Union[pd.Series, np.ndarray],
  ):
      """
      Fits the sm model using the concat of X and y.
      """
  
      # defensive X, y checks
      check_X_y(X, y, y_numeric=True)
  
      # force X, y to DataFrame, Series for later calculations
      X = pd.DataFrame(X)
      y = pd.Series(y)
  
      # force name so that name != None (causes errors in notears)
      y.name = y.name or "__target"
  
      # if self.dist_type_schema is None, assume all columns are continuous
      # NOTE: this is copied due to later insertions
      dist_type_schema = copy.deepcopy(self.dist_type_schema) or {
          col: "cont" for col in X.columns
      }
  
      if self.standardize:
          # only standardize the continuous dist type columns.
          self.continuous_col_idxs = [
              X.columns.get_loc(col)
              for col, alias in dist_type_schema.items()
              if alias == "cont"
          ]
  
          # copy X to prevet changes to underlying array data
          X = X.copy()
          self._ss_X = StandardScaler()
          X.iloc[
              :, self.continuous_col_idxs
          ] = self._ss_X.fit_transform(
              X.iloc[:, self.continuous_col_idxs].values
          )
  
          # if its a continuous target also standardize
          if self.target_dist_type == "cont":
              y = y.copy()
              self._ss_y = StandardScaler()
              y[:] = self._ss_y.fit_transform(
                  y.values.reshape(-1, 1)
              ).reshape(-1)
  
      # add the target to the dist_type_schema
      # NOTE: this must be done AFTER standardize
      dist_type_schema[y.name] = self.target_dist_type
  
      # preserve the feature and target colnames
      self._features = tuple(X.columns)
      self._target = y.name
  
      # concat X and y along column axis
      X = pd.concat([X, y], axis=1)
  
      # make copy to prevent mutability
      tabu_parent_nodes = copy.deepcopy(self.tabu_parent_nodes)
      if self.dependent_target:
          if tabu_parent_nodes is None:
              tabu_parent_nodes = [self._target]
          elif self._target not in tabu_parent_nodes:
              tabu_parent_nodes.append(self._target)
  
      # fit the structured model
      self.graph_ = notears.from_pandas(
          X,
          dist_type_schema=dist_type_schema,
          lasso_beta=self.alpha,
          ridge_beta=self.beta,
          hidden_layer_units=self.hidden_layer_units,
          w_threshold=self.threshold,
          tabu_edges=self.tabu_edges,
          tabu_parent_nodes=tabu_parent_nodes,
          tabu_child_nodes=self.tabu_child_nodes,
          use_bias=self.fit_intercept,
          **(self.notears_mlp_kwargs or {}),
      )
  
      # keep thresholding until the DAG constraint is enforced
      if self.enforce_dag:
          self.graph_.threshold_till_dag()
  
      return self
  
imports: import copy
  from abc import ABCMeta
  from typing import Dict, Iterable, List, Union
  import numpy
  import pandas
  from IPython.lib.display import IFrame
  from sklearn.base import BaseEstimator
  from sklearn.preprocessing import StandardScaler
  from sklearn.utils.validation import check_is_fitted, check_X_y
  from causalnex.plots import EDGE_STYLE, NODE_STYLE, display_plot_ipython, plot_structure
  from causalnex.structure.pytorch import notears
label_desc: Use image node_id 2 for calling the DAGBase obj's underlying member method code with example usage: obj.fit(X, y) and returns: self