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

Method fit

sklearn/kernel_approximation.py:148–182  ·  view source on GitHub ↗

Fit the model with X. Initializes the internal variables. The method needs no information about the distribution of data, so we only care about n_features in X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features)

(self, X, y=None)

Source from the content-addressed store, hash-verified

146
147 @_fit_context(prefer_skip_nested_validation=True)
148 def fit(self, X, y=None):
149 """Fit the model with X.
150
151 Initializes the internal variables. The method needs no information
152 about the distribution of data, so we only care about n_features in X.
153
154 Parameters
155 ----------
156 X : {array-like, sparse matrix} of shape (n_samples, n_features)
157 Training data, where `n_samples` is the number of samples
158 and `n_features` is the number of features.
159
160 y : array-like of shape (n_samples,) or (n_samples, n_outputs), \
161 default=None
162 Target values (None for unsupervised transformations).
163
164 Returns
165 -------
166 self : object
167 Returns the instance itself.
168 """
169 X = validate_data(self, X, accept_sparse="csc")
170 random_state = check_random_state(self.random_state)
171
172 n_features = X.shape[1]
173 if self.coef0 != 0:
174 n_features += 1
175
176 self.indexHash_ = random_state.randint(
177 0, high=self.n_components, size=(self.degree, n_features)
178 )
179
180 self.bitHash_ = random_state.choice(a=[-1, 1], size=(self.degree, n_features))
181 self._n_features_out = self.n_components
182 return self
183
184 def transform(self, X):
185 """Generate the feature map approximation for X.

Callers

nothing calls this directly

Calls 2

validate_dataFunction · 0.90
check_random_stateFunction · 0.90

Tested by

no test coverage detected