def fit(self, x, y, sample_weight=None):
        """Fit PreBinning algorithm.

        Parameters
        ----------
        x : array-like, shape = (n_samples)
            Data samples, where n_samples is the number of samples.

        y : array-like, shape = (n_samples)
            Target vector relative to x.

        sample_weight : array-like of shape (n_samples,) (default=None)
            Array of weights that are assigned to individual samples.

        Returns
        -------
        self : PreBinning
        """
        if self.method not in ("uniform", "quantile", "cart", "mdlp"):
            raise ValueError('Invalid value for prebinning method. Allowed '
                             'string values are "cart", "mdlp", "quantile" '
                             'and "uniform".')

        if self.problem_type not in ("classification", "regression"):
            raise ValueError('Invalid value for problem_type. Allowed '
                             'string values are "classification" and '
                             '"regression".')

        if self.problem_type == "regression" and self.method == "mdlp":
            raise ValueError("mdlp method can only handle binary "
                             "classification problems.")

        if self.method in ("uniform", "quantile"):
            unsup_kwargs = {"n_bins": self.n_bins, "strategy": self.method}
            unsup_kwargs.update(**self.kwargs)

            est = KBinsDiscretizer(**unsup_kwargs)
            est.fit(x.reshape(-1, 1), y)
            self._splits = est.bin_edges_[0][1:-1]

        elif self.method == "cart":
            cart_kwargs = {
                    "min_samples_leaf": self.min_bin_size,
                    "max_leaf_nodes": self.n_bins}

            if self.problem_type == "classification":
                cart_kwargs["class_weight"] = self.class_weight
                cart_kwargs.update(**self.kwargs)

                est = DecisionTreeClassifier(**cart_kwargs)
            else:
                cart_kwargs.update(**self.kwargs)
                est = DecisionTreeRegressor(**cart_kwargs)

            est.fit(x.reshape(-1, 1), y, sample_weight=sample_weight)
            splits = np.unique(est.tree_.threshold)
            self._splits = splits[splits != _tree.TREE_UNDEFINED]

        elif self.method == "mdlp":
            mdlp_kwargs = {"min_samples_leaf": self.min_bin_size}
            mdlp_kwargs.update(**self.kwargs)

            est = MDLP(**mdlp_kwargs)
            est.fit(x, y)
            self._splits = est.splits

        return self
Fit PreBinning algorithm.

        Parameters
        ----------
        x : array-like, shape = (n_samples)
            Data samples, where n_samples is the number of samples.

        y : array-like, shape = (n_samples)
            Target vector relative to x.

        sample_weight : array-like of shape (n_samples,) (default=None)
            Array of weights that are assigned to individual samples.

        Returns
        -------
        self : PreBinning
        
optbinning/binning/prebinning.py