def fit(self, X, y):
        """Fit the model according to the given training data.

        It build a forest of trees from the training set.

        Parameters
        ----------
        X : array-like, shape = (n_samples, n_timestamps)
            Univariate time series.

        y : array-like, shape = (n_samples,)
            Class labels for each sample.

        Returns
        -------
        self : object

        """
        # Extract some information from the dataset
        X, y = check_X_y(X, y)
        n_samples, n_timestamps = X.shape
        n_classes = np.unique(y).size

        bins = self._check_params()
        self._bins = bins

        # Create the instances of the feature extractor anf classifiers
        feature_extractor = IntervalFeatureExtractor(
            min_subsequence_size=self.min_subsequence_size,
            min_interval_size=self.min_interval_size,
            n_subsequences=self.n_subsequences,
            random_state=self.random_state
        )
        rfc = RandomForestClassifier(
            n_estimators=self.n_estimators,
            criterion=self.criterion,
            max_depth=self.max_depth,
            min_samples_split=self.min_samples_split,
            min_samples_leaf=self.min_samples_leaf,
            min_weight_fraction_leaf=self.min_weight_fraction_leaf,
            max_features=self.max_features,
            max_leaf_nodes=self.max_leaf_nodes,
            min_impurity_decrease=self.min_impurity_decrease,
            bootstrap=self.bootstrap,
            n_jobs=self.n_jobs,
            random_state=self.random_state,
            verbose=self.verbose,
            class_weight=self.class_weight,
            ccp_alpha=self.ccp_alpha,
            max_samples=self.max_samples,
            warm_start=False,
            oob_score=True
        )
        clf = RandomForestClassifier(
            n_estimators=self.n_estimators,
            criterion=self.criterion,
            max_depth=self.max_depth,
            min_samples_split=self.min_samples_split,
            min_samples_leaf=self.min_samples_leaf,
            min_weight_fraction_leaf=self.min_weight_fraction_leaf,
            max_features=self.max_features,
            max_leaf_nodes=self.max_leaf_nodes,
            min_impurity_decrease=self.min_impurity_decrease,
            bootstrap=self.bootstrap,
            oob_score=self.oob_score,
            n_jobs=self.n_jobs,
            random_state=self.random_state,
            verbose=self.verbose,
            class_weight=self.class_weight,
            ccp_alpha=self.ccp_alpha,
            max_samples=self.max_samples,
            warm_start=False,
        )

        # Fit the random forest and get out-of-bag probabilities
        X_features = feature_extractor.fit_transform(X)
        n_subsequences = feature_extractor.interval_indices_.shape[0]
        y_features = np.repeat(y, n_subsequences)
        rfc.fit(X_features, y_features)
        X_oob_proba = rfc.oob_decision_function_.reshape(
            n_samples, n_subsequences, n_classes)

        # Check for subsequences without OOB scores
        no_oob_scores = (
            (np.isnan(X_oob_proba).any() or
             np.all(X_oob_proba == 0., axis=2).any())
        )
        if no_oob_scores:
            raise ValueError(
                "At least one sample was never left out during the bootstrap. "
                "Increase the number of trees (n_estimators)."
            )

        # Bin the probabilities
        if isinstance(bins, (int, np.integer)):
            n_bins = bins
        else:
            n_bins = len(bins) - 1
        X_binned = histogram(X_oob_proba, bins, n_bins, n_samples, n_classes)

        # Fit a random forest on the binned probabilities
        clf.fit(X_binned, y)

        # Get attributes
        self.estimator_ = clf.estimator_
        self.classes_ = clf.classes_
        self.estimators_ = clf.estimators_
        self.feature_importances_ = clf.feature_importances_
        self.interval_indices_ = feature_extractor.interval_indices_
        self.min_subsequence_size_ = feature_extractor.min_subsequence_size_
        self.n_features_in_ = (
            clf.n_features_in_
            if hasattr(clf, 'n_features_in_')
            else clf.n_features_
        )
        self.oob_decision_function_ = getattr(
            clf, 'oob_decision_function_', None)
        self.oob_score_ = getattr(clf, 'oob_score_', None)

        self._feature_extractor = feature_extractor
        self._rfc = rfc
        self._clf = clf

        return self
Fit the model according to the given training data.

        It build a forest of trees from the training set.

        Parameters
        ----------
        X : array-like, shape = (n_samples, n_timestamps)
            Univariate time series.

        y : array-like, shape = (n_samples,)
            Class labels for each sample.

        Returns
        -------
        self : object

        
pyts/classification/tsbf.py