MCPcopy Index your code
hub / github.com/scikit-learn/scikit-learn / fit

Method fit

sklearn/multiclass.py:1163–1238  ·  view source on GitHub ↗

Fit underlying estimators. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Data. y : array-like of shape (n_samples,) Multi-class targets. **fit_params : dict Parameters passed to th

(self, X, y, **fit_params)

Source from the content-addressed store, hash-verified

1161 prefer_skip_nested_validation=False
1162 )
1163 def fit(self, X, y, **fit_params):
1164 """Fit underlying estimators.
1165
1166 Parameters
1167 ----------
1168 X : {array-like, sparse matrix} of shape (n_samples, n_features)
1169 Data.
1170
1171 y : array-like of shape (n_samples,)
1172 Multi-class targets.
1173
1174 **fit_params : dict
1175 Parameters passed to the ``estimator.fit`` method of each
1176 sub-estimator.
1177
1178 .. versionadded:: 1.4
1179 Only available if `enable_metadata_routing=True`. See
1180 :ref:`Metadata Routing User Guide <metadata_routing>` for more
1181 details.
1182
1183 Returns
1184 -------
1185 self : object
1186 Returns a fitted instance of self.
1187 """
1188 _raise_for_params(fit_params, self, "fit")
1189
1190 routed_params = process_routing(
1191 self,
1192 "fit",
1193 **fit_params,
1194 )
1195
1196 y = validate_data(self, X="no_validation", y=y)
1197
1198 random_state = check_random_state(self.random_state)
1199 check_classification_targets(y)
1200
1201 self.classes_ = np.unique(y)
1202 n_classes = self.classes_.shape[0]
1203 if n_classes == 0:
1204 raise ValueError(
1205 "OutputCodeClassifier can not be fit when no class is present."
1206 )
1207 n_estimators = int(n_classes * self.code_size)
1208
1209 # FIXME: there are more elaborate methods than generating the codebook
1210 # randomly.
1211 self.code_book_ = random_state.uniform(size=(n_classes, n_estimators))
1212 self.code_book_[self.code_book_ > 0.5] = 1.0
1213
1214 if hasattr(self.estimator, "decision_function"):
1215 self.code_book_[self.code_book_ != 1] = -1.0
1216 else:
1217 self.code_book_[self.code_book_ != 1] = 0.0
1218
1219 classes_index = {c: i for i, c in enumerate(self.classes_)}
1220

Callers 3

test_ecoc_fit_predictFunction · 0.95
test_ecoc_float_yFunction · 0.95

Calls 8

validate_dataFunction · 0.90
check_random_stateFunction · 0.90
_num_samplesFunction · 0.90
ParallelClass · 0.90
delayedFunction · 0.90
_raise_for_paramsFunction · 0.85
process_routingFunction · 0.85

Tested by 3

test_ecoc_fit_predictFunction · 0.76
test_ecoc_float_yFunction · 0.76