Transform n-dimensional array into 2D array of n_samples by n_features. This class reshapes an n-dimensional array into an n_samples * n_features array, usable by the estimators and transformers of scikit-learn. Attributes ---------- features_shape_ : tuple Stores the
| 293 | |
| 294 | |
| 295 | class Vectorizer(MNETransformerMixin, BaseEstimator): |
| 296 | """Transform n-dimensional array into 2D array of n_samples by n_features. |
| 297 | |
| 298 | This class reshapes an n-dimensional array into an n_samples * n_features |
| 299 | array, usable by the estimators and transformers of scikit-learn. |
| 300 | |
| 301 | Attributes |
| 302 | ---------- |
| 303 | features_shape_ : tuple |
| 304 | Stores the original shape of data. |
| 305 | |
| 306 | Examples |
| 307 | -------- |
| 308 | >>> from sklearn.linear_model import LogisticRegression |
| 309 | >>> from sklearn.pipeline import make_pipeline |
| 310 | >>> from sklearn.preprocessing import StandardScaler |
| 311 | >>> clf = make_pipeline(Vectorizer(), StandardScaler(), LogisticRegression()) |
| 312 | """ |
| 313 | |
| 314 | def fit(self, X, y=None): |
| 315 | """Store the shape of the features of X. |
| 316 | |
| 317 | Parameters |
| 318 | ---------- |
| 319 | X : array-like |
| 320 | The data to fit. Can be, for example a list, or an array of at |
| 321 | least 2d. The first dimension must be of length n_samples, where |
| 322 | samples are the independent samples used by the estimator |
| 323 | (e.g. n_epochs for epoched data). |
| 324 | y : None | array, shape (n_samples,) |
| 325 | Used for scikit-learn compatibility. |
| 326 | |
| 327 | Returns |
| 328 | ------- |
| 329 | self : instance of Vectorizer |
| 330 | Return the modified instance. |
| 331 | """ |
| 332 | X = self._check_data(X, y=y, atleast_3d=False, fit=True, check_n_features=False) |
| 333 | self.features_shape_ = X.shape[1:] |
| 334 | return self |
| 335 | |
| 336 | def transform(self, X): |
| 337 | """Convert given array into two dimensions. |
| 338 | |
| 339 | Parameters |
| 340 | ---------- |
| 341 | X : array-like |
| 342 | The data to fit. Can be, for example a list, or an array of at |
| 343 | least 2d. The first dimension must be of length n_samples, where |
| 344 | samples are the independent samples used by the estimator |
| 345 | (e.g. n_epochs for epoched data). |
| 346 | |
| 347 | Returns |
| 348 | ------- |
| 349 | X : array, shape (n_samples, n_features) |
| 350 | The transformed data. |
| 351 | """ |
| 352 | X = self._check_data(X, atleast_3d=False) |
no outgoing calls