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

Method transform

sklearn/kernel_approximation.py:705–749  ·  view source on GitHub ↗

Apply approximate feature map to X. Parameters ---------- X : {array-like, sparse matrix}, shape (n_samples, n_features) Training data, where `n_samples` is the number of samples and `n_features` is the number of features. Returns ---

(self, X)

Source from the content-addressed store, hash-verified

703 return self
704
705 def transform(self, X):
706 """Apply approximate feature map to X.
707
708 Parameters
709 ----------
710 X : {array-like, sparse matrix}, shape (n_samples, n_features)
711 Training data, where `n_samples` is the number of samples
712 and `n_features` is the number of features.
713
714 Returns
715 -------
716 X_new : {ndarray, sparse matrix}, \
717 shape = (n_samples, n_features * (2*sample_steps - 1))
718 Whether the return value is an array or sparse matrix depends on
719 the type of the input X.
720 """
721 X = validate_data(
722 self, X, accept_sparse="csr", reset=False, ensure_non_negative=True
723 )
724 sparse = sp.issparse(X)
725
726 if self.sample_interval is None:
727 # See figure 2 c) of "Efficient additive kernels via explicit feature maps"
728 # <http://www.robots.ox.ac.uk/~vedaldi/assets/pubs/vedaldi11efficient.pdf>
729 # A. Vedaldi and A. Zisserman, Pattern Analysis and Machine Intelligence,
730 # 2011
731 if self.sample_steps == 1:
732 sample_interval = 0.8
733 elif self.sample_steps == 2:
734 sample_interval = 0.5
735 elif self.sample_steps == 3:
736 sample_interval = 0.4
737 else:
738 raise ValueError(
739 "If sample_steps is not in [1, 2, 3],"
740 " you need to provide sample_interval"
741 )
742 else:
743 sample_interval = self.sample_interval
744
745 # zeroth component
746 # 1/cosh = sech
747 # cosh(0) = 1.0
748 transf = self._transform_sparse if sparse else self._transform_dense
749 return transf(X, self.sample_steps, sample_interval)
750
751 def get_feature_names_out(self, input_features=None):
752 """Get output feature names for transformation.

Calls 1

validate_dataFunction · 0.90

Tested by 2