MCPcopy
hub / github.com/scikit-learn/scikit-learn / fit

Method fit

sklearn/multioutput.py:708–822  ·  view source on GitHub ↗

Fit the model to data matrix X and targets Y. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input data. Y : array-like of shape (n_samples, n_classes) The target values. **fit_params : dic

(self, X, Y, **fit_params)

Source from the content-addressed store, hash-verified

706
707 @abstractmethod
708 def fit(self, X, Y, **fit_params):
709 """Fit the model to data matrix X and targets Y.
710
711 Parameters
712 ----------
713 X : {array-like, sparse matrix} of shape (n_samples, n_features)
714 The input data.
715
716 Y : array-like of shape (n_samples, n_classes)
717 The target values.
718
719 **fit_params : dict of string -> object
720 Parameters passed to the `fit` method of each step.
721
722 .. versionadded:: 0.23
723
724 Returns
725 -------
726 self : object
727 Returns a fitted instance.
728 """
729 X, Y = validate_data(self, X, Y, multi_output=True, accept_sparse=True)
730
731 random_state = check_random_state(self.random_state)
732 self.order_ = self.order
733 if isinstance(self.order_, tuple):
734 self.order_ = np.array(self.order_)
735
736 if self.order_ is None:
737 self.order_ = np.array(range(Y.shape[1]))
738 elif isinstance(self.order_, str):
739 if self.order_ == "random":
740 self.order_ = random_state.permutation(Y.shape[1])
741 elif sorted(self.order_) != list(range(Y.shape[1])):
742 raise ValueError("invalid order")
743
744 self.estimators_ = [clone(self.estimator) for _ in range(Y.shape[1])]
745
746 if self.cv is None:
747 Y_pred_chain = Y[:, self.order_]
748 if sp.issparse(X):
749 X_aug = sp.hstack((X, Y_pred_chain), format="lil")
750 X_aug = X_aug.tocsr()
751 else:
752 X_aug = np.hstack((X, Y_pred_chain))
753
754 elif sp.issparse(X):
755 # TODO: remove this condition check when the minimum supported scipy version
756 # doesn't support sparse matrices anymore
757 if not sp.isspmatrix(X):
758 # if `X` is a scipy sparse dok_array, we convert it to a sparse
759 # coo_array format before hstacking, it's faster; see
760 # https://github.com/scipy/scipy/issues/20060#issuecomment-1937007039:
761 if X.format == "dok":
762 X = sp.coo_array(X)
763 # in case that `X` is a sparse array we create `Y_pred_chain` as a
764 # sparse array format:
765 Y_pred_chain = sp.coo_array((X.shape[0], Y.shape[1]))

Callers 4

_fit_estimatorFunction · 0.45
fitMethod · 0.45
fitMethod · 0.45
fitMethod · 0.45

Calls 11

_log_messageMethod · 0.95
validate_dataFunction · 0.90
check_random_stateFunction · 0.90
cloneFunction · 0.90
BunchClass · 0.90
_check_response_methodFunction · 0.90
_print_elapsed_timeFunction · 0.90
cross_val_predictFunction · 0.90
_routing_enabledFunction · 0.85
process_routingFunction · 0.85
hstackMethod · 0.45

Tested by

no test coverage detected