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

Method fit

sklearn/dummy.py:162–250  ·  view source on GitHub ↗

Fit the baseline classifier. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data. y : array-like of shape (n_samples,) or (n_samples, n_outputs) Target values. sample_weight : array-like of shape (n_sa

(self, X, y, sample_weight=None)

Source from the content-addressed store, hash-verified

160
161 @_fit_context(prefer_skip_nested_validation=True)
162 def fit(self, X, y, sample_weight=None):
163 """Fit the baseline classifier.
164
165 Parameters
166 ----------
167 X : array-like of shape (n_samples, n_features)
168 Training data.
169
170 y : array-like of shape (n_samples,) or (n_samples, n_outputs)
171 Target values.
172
173 sample_weight : array-like of shape (n_samples,), default=None
174 Sample weights.
175
176 Returns
177 -------
178 self : object
179 Returns the instance itself.
180 """
181 validate_data(self, X, skip_check_array=True)
182
183 self._strategy = self.strategy
184
185 if self._strategy == "uniform" and sp.issparse(y):
186 y = y.toarray()
187 warnings.warn(
188 (
189 "A local copy of the target data has been converted "
190 "to a numpy array. Predicting on sparse target data "
191 "with the uniform strategy would not save memory "
192 "and would be slower."
193 ),
194 UserWarning,
195 )
196
197 self.sparse_output_ = sp.issparse(y)
198
199 if not self.sparse_output_:
200 y = np.asarray(y)
201 y = np.atleast_1d(y)
202
203 if y.ndim == 1:
204 y = np.reshape(y, (-1, 1))
205
206 self.n_outputs_ = y.shape[1]
207
208 check_consistent_length(X, y)
209
210 if sample_weight is not None:
211 sample_weight = _check_sample_weight(sample_weight, X)
212
213 if self._strategy == "constant":
214 if self.constant is None:
215 raise ValueError(
216 "Constant target value has to be specified "
217 "when the constant strategy is used."
218 )
219 else:

Calls 6

validate_dataFunction · 0.90
check_consistent_lengthFunction · 0.90
_check_sample_weightFunction · 0.90
class_distributionFunction · 0.90
anyFunction · 0.85
formatMethod · 0.80