package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `RBFSampler
]
type t = [ `BaseEstimator | `Object | `RBFSampler | `TransformerMixin ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val as_transformer : t -> [ `TransformerMixin ] Obj.t
val as_estimator : t -> [ `BaseEstimator ] Obj.t
val create : ?gamma:float -> ?n_components:int -> ?random_state:int -> unit -> t

Approximates feature map of an RBF kernel by Monte Carlo approximation of its Fourier transform.

It implements a variant of Random Kitchen Sinks.1

Read more in the :ref:`User Guide <rbf_kernel_approx>`.

Parameters ---------- gamma : float Parameter of RBF kernel: exp(-gamma * x^2)

n_components : int Number of Monte Carlo samples per original feature. Equals the dimensionality of the computed feature space.

random_state : int, RandomState instance or None, optional (default=None) Pseudo-random number generator to control the generation of the random weights and random offset when fitting the training data. Pass an int for reproducible output across multiple function calls. See :term:`Glossary <random_state>`.

Attributes ---------- random_offset_ : ndarray of shape (n_components,), dtype=float64 Random offset used to compute the projection in the `n_components` dimensions of the feature space.

random_weights_ : ndarray of shape (n_features, n_components), dtype=float64 Random projection directions drawn from the Fourier transform of the RBF kernel.

Examples -------- >>> from sklearn.kernel_approximation import RBFSampler >>> from sklearn.linear_model import SGDClassifier >>> X = [0, 0], [1, 1], [1, 0], [0, 1] >>> y = 0, 0, 1, 1 >>> rbf_feature = RBFSampler(gamma=1, random_state=1) >>> X_features = rbf_feature.fit_transform(X) >>> clf = SGDClassifier(max_iter=5, tol=1e-3) >>> clf.fit(X_features, y) SGDClassifier(max_iter=5) >>> clf.score(X_features, y) 1.0

Notes ----- See 'Random Features for Large-Scale Kernel Machines' by A. Rahimi and Benjamin Recht.

1 'Weighted Sums of Random Kitchen Sinks: Replacing minimization with randomization in learning' by A. Rahimi and Benjamin Recht. (https://people.eecs.berkeley.edu/~brecht/papers/08.rah.rec.nips.pdf)

val fit : ?y:Py.Object.t -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> t

Fit the model with X.

Samples random projection according to n_features.

Parameters ---------- X : array-like, sparse matrix, shape (n_samples, n_features) Training data, where n_samples in the number of samples and n_features is the number of features.

Returns ------- self : object Returns the transformer.

val fit_transform : ?y:[> `ArrayLike ] Np.Obj.t -> ?fit_params:(string * Py.Object.t) list -> x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters ---------- X : array-like, sparse matrix, dataframe of shape (n_samples, n_features)

y : ndarray of shape (n_samples,), default=None Target values.

**fit_params : dict Additional fit parameters.

Returns ------- X_new : ndarray array of shape (n_samples, n_features_new) Transformed array.

val get_params : ?deep:bool -> [> tag ] Obj.t -> Dict.t

Get parameters for this estimator.

Parameters ---------- deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns ------- params : mapping of string to any Parameter names mapped to their values.

val set_params : ?params:(string * Py.Object.t) list -> [> tag ] Obj.t -> t

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form ``<component>__<parameter>`` so that it's possible to update each component of a nested object.

Parameters ---------- **params : dict Estimator parameters.

Returns ------- self : object Estimator instance.

val transform : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Apply the approximate feature map to X.

Parameters ---------- X : array-like, sparse matrix, shape (n_samples, n_features) New data, where n_samples in the number of samples and n_features is the number of features.

Returns ------- X_new : array-like, shape (n_samples, n_components)

val random_offset_ : t -> Py.Object.t

Attribute random_offset_: get value or raise Not_found if None.

val random_offset_opt : t -> Py.Object.t option

Attribute random_offset_: get value as an option.

val random_weights_ : t -> Py.Object.t

Attribute random_weights_: get value or raise Not_found if None.

val random_weights_opt : t -> Py.Object.t option

Attribute random_weights_: get value as an option.

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty-print the object to a formatter.