Standardize a dataset along any axis.
Center to the mean and component wise scale to unit variance.
Read more in the User Guide.
The data to center and scale.
axis used to compute the means and standard deviations along. If 0, independently standardize each feature, otherwise (if 1) standardize each sample.
If True, center the data before scaling.
If True, scale the data to unit variance (or equivalently, unit standard deviation).
set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSC matrix and if axis is 1).
The transformed data.
See also
Performs scaling to unit variance using the Transformer API (e.g. as part of a preprocessing Pipeline).
This implementation will refuse to center scipy.sparse matrices since it would make them non-sparse and would potentially crash the program with memory exhaustion problems.
Instead the caller is expected to either set explicitly with_mean=False (in that case, only variance scaling will be performed on the features of the CSC matrix) or to call X.toarray() if he/she expects the materialized dense array to fit in memory.
To avoid memory copy the caller should pass a CSC matrix.
NaNs are treated as missing values: disregarded to compute the statistics, and maintained during the data transformation.
We use a biased estimator for the standard deviation, equivalent to numpy.std(x, ddof=0). Note that the choice of ddof is unlikely to affect model performance.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
Warning
Risk of data leak
Do not use scale unless you know what you are doing. A common mistake is to apply it to the entire data before splitting into training and test sets. This will bias the model evaluation because information would have leaked from the test set to the training set. In general, we recommend using StandardScaler within a Pipeline in order to prevent most risks of data leaking: pipe = make_pipeline(StandardScaler(), LogisticRegression()).


Find a ‘safe’ number of components to randomly project to.
The distortion introduced by a random projection p only changes the distance between two points by a factor (1 +- eps) in an euclidean space with good probability. The projection p is an eps-embedding as defined by:
(1 - eps) ||u - v||^2 < ||p(u) - p(v)||^2 < (1 + eps) ||u - v||^2
Where u and v are any rows taken from a dataset of shape (n_samples, n_features), eps is in ]0, 1[ and p is a projection by a random Gaussian N(0, 1) matrix of shape (n_components, n_features) (or a sparse Achlioptas matrix).
The minimum number of components to guarantee the eps-embedding is given by:
n_components >= 4 log(n_samples) / (eps^2 / 2 - eps^3 / 3)
Note that the number of dimensions is independent of the original number of features but instead depends on the size of the dataset: the larger the dataset, the higher is the minimal dimensionality of an eps-embedding.
Read more in the User Guide.
Number of samples that should be a integer greater than 0. If an array is given, it will compute a safe number of components array-wise.
Maximum distortion rate in the range (0,1 ) as defined by the Johnson-Lindenstrauss lemma. If an array is given, it will compute a safe number of components array-wise.
The minimal number of components to guarantee with good probability an eps-embedding with n_samples.
https://en.wikipedia.org/wiki/Johnson%E2%80%93Lindenstrauss_lemma
Sanjoy Dasgupta and Anupam Gupta, 1999, “An elementary proof of the Johnson-Lindenstrauss Lemma.” http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.3654
The Johnson-Lindenstrauss bound for embedding with random projections


Set global scikit-learn configuration
New in version 0.19.
If True, validation for finiteness will be skipped, saving time, but leading to potential crashes. If False, validation for finiteness will be performed, avoiding error. Global default: False.
New in version 0.19.
If set, scikit-learn will attempt to limit the size of temporary arrays to this number of MiB (per job when parallelised), often saving both computation time and memory on expensive operations that can be performed in chunks. Global default: 1024.
New in version 0.20.
If True, only the parameters that were set to non-default values will be printed when printing an estimator. For example, print(SVC()) while True will only print ‘SVC()’ while the default behaviour would be to print ‘SVC(C=1.0, cache_size=200, …)’ with all the non-changed parameters.
New in version 0.21.
If ‘diagram’, estimators will be displayed as a diagram in a Jupyter lab or notebook context. If ‘text’, estimators will be displayed as text. Default is ‘text’.
New in version 0.23.
See also
Context manager for global scikit-learn configuration.
Retrieve current values of the global configuration.
Release Highlights for scikit-learn 0.23
Compact estimator representations
Column Transformer with Mixed Types


Print useful debugging information”
New in version 0.20.


Return the lowest bound for C such that for C in (l1_min_C, infinity) the model is guaranteed not to be empty. This applies to l1 penalized classifiers, such as LinearSVC with penalty=’l1’ and linear_model.LogisticRegression with penalty=’l1’.
This value is valid if class_weight parameter in fit() is not set.
Training vector, where n_samples in the number of samples and n_features is the number of features.
Target vector relative to X.
Specifies the loss function. With ‘squared_hinge’ it is the squared hinge loss (a.k.a. L2 loss). With ‘log’ it is the loss of logistic regression models.
Specifies if the intercept should be fitted by the model. It must match the fit() method parameter.
when fit_intercept is True, instance vector x becomes [x, intercept_scaling], i.e. a “synthetic” feature with constant value equals to intercept_scaling is appended to the instance vector. It must match the fit() method parameter.
minimum value for C
Regularization path of L1- Logistic Regression


Export a decision tree in DOT format.
This function generates a GraphViz representation of the decision tree, which is then written into out_file. Once exported, graphical renderings can be generated using, for example:
The sample counts that are shown are weighted with any sample_weights that might be present.
Read more in the User Guide.
The decision tree to be exported to GraphViz.
Handle or name of the output file. If None, the result is returned as a string.
Changed in version 0.20: Default of out_file changed from “tree.dot” to None.
The maximum depth of the representation. If None, the tree is fully generated.
Names of each of the features. If None generic names will be used (“feature_0”, “feature_1”, …).
Names of each of the target classes in ascending numerical order. Only relevant for classification and not supported for multi-output. If True, shows a symbolic representation of the class name.
Whether to show informative labels for impurity, etc. Options include ‘all’ to show at every node, ‘root’ to show only at the top root node, or ‘none’ to not show at any node.
When set to True, paint nodes to indicate majority class for classification, extremity of values for regression, or purity of node for multi-output.
When set to True, draw all leaf nodes at the bottom of the tree.
When set to True, show the impurity at each node.
When set to True, show the ID number on each node.
When set to True, change the display of ‘values’ and/or ‘samples’ to be proportions and percentages respectively.
When set to True, orient tree left to right rather than top-down.
When set to True, draw node boxes with rounded corners and use Helvetica fonts instead of Times-Roman.
When set to False, ignore special characters for PostScript compatibility.
Number of digits of precision for floating point in the values of impurity, threshold and value attributes of each node.
String representation of the input tree in GraphViz dot format. Only returned if out_file is None.
New in version 0.18.


Build a text report showing the rules of a decision tree.
Note that backwards compatibility may not be supported.
The decision tree estimator to be exported. It can be an instance of DecisionTreeClassifier or DecisionTreeRegressor.
A list of length n_features containing the feature names. If None generic names will be used (“feature_0”, “feature_1”, …).
Only the first max_depth levels of the tree are exported. Truncated branches will be marked with “…”.
Number of spaces between edges. The higher it is, the wider the result.
Number of decimal digits to display.
If true the classification weights will be exported on each leaf. The classification weights are the number of samples each class.
Text summary of all the rules in the decision tree.


Plot a decision tree.
The sample counts that are shown are weighted with any sample_weights that might be present.
The visualization is fit automatically to the size of the axis. Use the figsize or dpi arguments of plt.figure to control the size of the rendering.
Read more in the User Guide.
New in version 0.21.
The decision tree to be plotted.
The maximum depth of the representation. If None, the tree is fully generated.
Names of each of the features. If None, generic names will be used (“X[0]”, “X[1]”, …).
Names of each of the target classes in ascending numerical order. Only relevant for classification and not supported for multi-output. If True, shows a symbolic representation of the class name.
Whether to show informative labels for impurity, etc. Options include ‘all’ to show at every node, ‘root’ to show only at the top root node, or ‘none’ to not show at any node.
When set to True, paint nodes to indicate majority class for classification, extremity of values for regression, or purity of node for multi-output.
When set to True, show the impurity at each node.
When set to True, show the ID number on each node.
When set to True, change the display of ‘values’ and/or ‘samples’ to be proportions and percentages respectively.
This parameter has no effect on the matplotlib tree visualisation and it is kept here for backward compatibility.
Deprecated since version 0.23: rotate is deprecated in 0.23 and will be removed in 1.0 (renaming of 0.25).
When set to True, draw node boxes with rounded corners and use Helvetica fonts instead of Times-Roman.
Number of digits of precision for floating point in the values of impurity, threshold and value attributes of each node.
Axes to plot to. If None, use current axis. Any previous content is cleared.
Size of text font. If None, determined automatically to fit figure.
List containing the artists for the annotation boxes making up the tree.
Plot the decision surface of a decision tree on the iris dataset
Understanding the decision tree structure


Get a list of all estimators from sklearn.
This function crawls the module and gets all classes that inherit from BaseEstimator. Classes that are defined in test-modules are not included.
Which kind of estimators should be returned. If None, no filter is applied and all estimators are returned. Possible values are ‘classifier’, ‘regressor’, ‘cluster’ and ‘transformer’ to get estimators only of these specific types, or a list of these to get the estimators that fit at least one of the types.
List of (name, class), where name is the class name as string and class is the actuall type of the class.


Find the minimum value of an array over positive values
Returns a huge value if none of the values are positive


Throw a ValueError if X contains NaN or infinity.


Converts an array-like to an array of floats.
The new dtype will be np.float32 or np.float64, depending on the original type. The function can create a copy or modify the argument depending on the argument copy.
If True, a copy of X will be created. If False, a copy may still be returned if X’s dtype is not a floating point type.
Whether to raise an error on np.inf, np.nan, pd.NA in X. The possibilities are:
New in version 0.20: force_all_finite accepts the string 'allow-nan'.
Changed in version 0.23: Accepts pd.NA and converts it into np.nan
An array of type float.


Container object exposing keys as attributes.
Bunch objects are sometimes used as an output for functions and methods. They extend dictionaries by enabling values to be accessed by key, bunch["value_key"], or by an attribute, bunch.value_key.
Species distribution modeling


Input validation on an array, list, sparse matrix or similar.
By default, the input is checked to be a non-empty 2D array containing only finite values. If the dtype of the array is object, attempt converting to float, raising on failure.
Input object to check / convert.
String[s] representing allowed sparse matrix formats, such as ‘csc’, ‘csr’, etc. If the input is sparse but not in the allowed format, it will be converted to the first listed format. True allows the input to be any format. False means that a sparse matrix input will raise an error.
If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by accept_sparse, accept_large_sparse=False will cause it to be accepted only if its indices are stored with a 32-bit dtype.
New in version 0.20.
Data type of result. If None, the dtype of the input is preserved. If “numeric”, dtype is preserved unless array.dtype is object. If dtype is a list of types, conversion on the first type is only performed if the dtype of the input is not in the list.
Whether an array will be forced to be fortran or c-style. When order is None (default), then if copy=False, nothing is ensured about the memory layout of the output array; otherwise (copy=True) the memory layout of the returned array is kept as close as possible to the original array.
Whether a forced copy will be triggered. If copy=False, a copy might be triggered by a conversion.
Whether to raise an error on np.inf, np.nan, pd.NA in array. The possibilities are:
New in version 0.20: force_all_finite accepts the string 'allow-nan'.
Changed in version 0.23: Accepts pd.NA and converts it into np.nan
Whether to raise a value error if array is not 2D.
Whether to allow array.ndim > 2.
Make sure that the array has a minimum number of samples in its first axis (rows for a 2D array). Setting to 0 disables this check.
Make sure that the 2D array has some minimum number of features (columns). The default value of 1 rejects empty datasets. This check is only enforced when the input data has effectively 2 dimensions or is originally 1D and ensure_2d is True. Setting to 0 disables this check.
If passed, include the name of the estimator in warning messages.
The converted and validated array.


Check that all arrays have consistent first dimensions.
Checks whether all objects in arrays have the same shape or length.
Objects that will be checked for consistent length.


Turn seed into a np.random.RandomState instance
If seed is None, return the RandomState singleton used by np.random. If seed is an int, return a new RandomState instance seeded with seed. If seed is already a RandomState instance, return it. Otherwise raise ValueError.
Empirical evaluation of the impact of k-means initialization
MNIST classification using multinomial logistic + L1
Manifold Learning methods on a severed sphere
Isotonic Regression
Face completion with a multi-output estimators
Scaling the regularization parameter for SVCs


Validate scalar parameters type and value.
The scalar parameter to validate.
The name of the parameter to be printed in error messages.
Acceptable data types for the parameter.
The minimum valid value the parameter can take. If None (default) it is implied that the parameter does not have a lower bound.
The maximum valid value the parameter can take. If None (default) it is implied that the parameter does not have an upper bound.
If the parameter’s type does not match the desired type.
If the parameter’s value violates the given bounds.


Input validation for standard estimators.
Checks X and y for consistent length, enforces X to be 2D and y 1D. By default, X is checked to be non-empty and containing only finite values. Standard input checks are also applied to y, such as checking that y does not have np.nan or np.inf targets. For multi-label y, set multi_output=True to allow 2D and sparse y. If the dtype of X is object, attempt converting to float, raising on failure.
Input data.
Labels.
String[s] representing allowed sparse matrix formats, such as ‘csc’, ‘csr’, etc. If the input is sparse but not in the allowed format, it will be converted to the first listed format. True allows the input to be any format. False means that a sparse matrix input will raise an error.
If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by accept_sparse, accept_large_sparse will cause it to be accepted only if its indices are stored with a 32-bit dtype.
New in version 0.20.
Data type of result. If None, the dtype of the input is preserved. If “numeric”, dtype is preserved unless array.dtype is object. If dtype is a list of types, conversion on the first type is only performed if the dtype of the input is not in the list.
Whether an array will be forced to be fortran or c-style.
Whether a forced copy will be triggered. If copy=False, a copy might be triggered by a conversion.
Whether to raise an error on np.inf, np.nan, pd.NA in X. This parameter does not influence whether y can have np.inf, np.nan, pd.NA values. The possibilities are:
New in version 0.20: force_all_finite accepts the string 'allow-nan'.
Changed in version 0.23: Accepts pd.NA and converts it into np.nan
Whether to raise a value error if X is not 2D.
Whether to allow X.ndim > 2.
Whether to allow 2D y (array or sparse matrix). If false, y will be validated as a vector. y cannot have np.nan or np.inf values if multi_output=True.
Make sure that X has a minimum number of samples in its first axis (rows for a 2D array).
Make sure that the 2D array has some minimum number of features (columns). The default value of 1 rejects empty datasets. This check is only enforced when X has effectively 2 dimensions or is originally 1D and ensure_2d is True. Setting to 0 disables this check.
Whether to ensure that y has a numeric type. If dtype of y is object, it is converted to float64. Should only be used for regression algorithms.
If passed, include the name of the estimator in warning messages.
The converted and validated X.
The converted and validated y.


Estimate class weights for unbalanced datasets.
If ‘balanced’, class weights will be given by n_samples / (n_classes * np.bincount(y)). If a dictionary is given, keys are classes and values are corresponding class weights. If None is given, the class weights will be uniform.
Array of the classes occurring in the data, as given by np.unique(y_org) with y_org the original class labels.
Array of original class labels per sample.
Array with class_weight_vect[i] the weight for i-th class.
The “balanced” heuristic is inspired by Logistic Regression in Rare Events Data, King, Zen, 2001.


Estimate sample weights by class for unbalanced datasets.
Weights associated with classes in the form {class_label: weight}. If not given, all classes are supposed to have weight one. For multi-output problems, a list of dicts can be provided in the same order as the columns of y.
Note that for multioutput (including multilabel) weights should be defined for each class of every column in its own dict. For example, for four-class multilabel classification weights should be [{0: 1, 1: 1}, {0: 1, 1: 5}, {0: 1, 1: 1}, {0: 1, 1: 1}] instead of [{1:1}, {2:5}, {3:1}, {4:1}].
The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data: n_samples / (n_classes * np.bincount(y)).
For multi-output, the weights of each column of y will be multiplied.
Array of original class labels per sample.
Array of indices to be used in a subsample. Can be of length less than n_samples in the case of a subsample, or equal to n_samples in the case of a bootstrap subsample with repeated indices. If None, the sample weight will be calculated over the full sample. Only “balanced” is supported for class_weight if this is provided.
Array with sample weights as applied to the original y.


Decorator to mark a function or class as deprecated.
Issue a warning when the function is called/the class is instantiated and adds a warning to the docstring.
The optional extra argument will be appended to the deprecation message and the docstring. Note: to use this with the default value for extra, put in an empty of parentheses:
To be added to the deprecation messages.


Check if estimator adheres to scikit-learn conventions.
This estimator will run an extensive test-suite for input validation, shapes, etc, making sure that the estimator complies with scikit-learn conventions as detailed in Rolling your own estimator. Additional tests for classifiers, regressors, clustering or transformers will be run if the Estimator class inherits from the corresponding mixin from sklearn.base.
Setting generate_only=True returns a generator that yields (estimator, check) tuples where the check can be called independently from each other, i.e. check(estimator). This allows all checks to be run independently and report the checks that are failing.
scikit-learn provides a pytest specific decorator, parametrize_with_checks, making it easier to test multiple estimators.
Estimator instance to check.
Changed in version 0.24: Passing a class was deprecated in version 0.23, and support for classes was removed in 0.24.
When False, checks are evaluated when check_estimator is called. When True, check_estimator returns a generator that yields (estimator, check) tuples. The check is run by calling check(estimator).
New in version 0.22.
Generator that yields (estimator, check) tuples. Returned when generate_only=True.


Pytest specific decorator for parametrizing estimator checks.
The id of each check is set to be a pprint version of the estimator and the name of the check with its keyword arguments. This allows to use pytest -k to specify which tests to run:
Estimators to generated checks for.
Changed in version 0.24: Passing a class was deprecated in version 0.23, and support for classes was removed in 0.24. Pass an instance instead.
New in version 0.24.
Release Highlights for scikit-learn 0.22


Build a HTML representation of an estimator.
Read more in the User Guide.
The estimator to visualize.
HTML representation of estimator.


Compute density of a sparse vector.
The sparse vector.
The density of w, between 0 and 1.
Classification of text documents using sparse features


Compute log(det(A)) for A symmetric.
Equivalent to : np.log(nl.det(A)) but more robust. It returns -Inf if det(A) is non positive or is not defined.
The matrix.


Computes an orthonormal matrix whose range approximates the range of A.
The input data matrix.
Size of the return array.
Number of power iterations used to stabilize the result.
Whether the power iterations are normalized with step-by-step QR factorization (the slowest but most accurate), ‘none’ (the fastest but numerically unstable when n_iter is large, e.g. typically 5 or larger), or ‘LU’ factorization (numerically stable but can lose slightly in accuracy). The ‘auto’ mode applies no normalization if n_iter <= 2 and switches to LU otherwise.
New in version 0.18.
The seed of the pseudo random number generator to use when shuffling the data, i.e. getting the random vectors to initialize the algorithm. Pass an int for reproducible results across multiple function calls. See Glossary.
A (size x size) projection matrix, the range of which approximates well the range of the input matrix A.
Follows Algorithm 4.3 of Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions Halko, et al., 2009 (arXiv:909) https://arxiv.org/pdf/0909.4061.pdf
An implementation of a randomized algorithm for principal component analysis A. Szlam et al. 2014


Computes a truncated randomized SVD.
Matrix to decompose.
Number of singular values and vectors to extract.
Additional number of random vectors to sample the range of M so as to ensure proper conditioning. The total number of random vectors used to find the range of M is n_components + n_oversamples. Smaller number can improve speed but can negatively impact the quality of approximation of singular vectors and singular values.
Number of power iterations. It can be used to deal with very noisy problems. When ‘auto’, it is set to 4, unless n_components is small (< .1 * min(X.shape)) n_iter in which case is set to 7. This improves precision with few components.
Changed in version 0.18.
Whether the power iterations are normalized with step-by-step QR factorization (the slowest but most accurate), ‘none’ (the fastest but numerically unstable when n_iter is large, e.g. typically 5 or larger), or ‘LU’ factorization (numerically stable but can lose slightly in accuracy). The ‘auto’ mode applies no normalization if n_iter <= 2 and switches to LU otherwise.
New in version 0.18.
Whether the algorithm should be applied to M.T instead of M. The result should approximately be the same. The ‘auto’ mode will trigger the transposition if M.shape[1] > M.shape[0] since this implementation of randomized SVD tend to be a little faster in that case.
Changed in version 0.18.
The output of a singular value decomposition is only unique up to a permutation of the signs of the singular vectors. If flip_sign is set to True, the sign ambiguity is resolved by making the largest loadings for each component in the left singular vectors positive.
The seed of the pseudo random number generator to use when shuffling the data, i.e. getting the random vectors to initialize the algorithm. Pass an int for reproducible results across multiple function calls. See Glossary.
This algorithm finds a (usually very good) approximate truncated singular value decomposition using randomization to speed up the computations. It is particularly fast on large matrices on which you wish to extract only a small number of components. In order to obtain further speed up, n_iter can be set <=2 (at the cost of loss of precision).


Dot product that handle the sparse matrix case correctly.
When False, a and b both being sparse will yield sparse output. When True, output will always be a dense array.
Sparse if a and b are sparse and dense_output=False.


Returns an array of the weighted modal (most common) value in a.
If there is more than one such value, only the first is returned. The bin-count for the modal bins is also returned.
This is an extension of the algorithm in scipy.stats.mode.
n-dimensional array of which to find mode(s).
n-dimensional array of weights for each value.
Axis along which to operate. Default is 0, i.e. the first axis.
Array of modal values.
Array of weighted counts for each mode.
See also
The value 4 appears three times: with uniform weights, the result is simply the mode of the distribution.
The value 2 has the highest score: it appears twice with weights of 1.5 and 2: the sum of these is 3.5.


Generator to create n_packs slices going up to n.
Number of slices to generate.
Number of samples. Pass n_samples when the slices are to be used for sparse matrix indexing; slicing off-the-end raises an exception, while it works for NumPy arrays.
Poisson regression and non-normal loss


Return the shortest path length from source to all reachable nodes.
Returns a dictionary of shortest path lengths keyed by target.
Adjacency matrix of the graph. Sparse matrix of format LIL is preferred.
Starting node for path.
Depth to stop the search - only paths of length <= cutoff are returned.


Perform a shortest-path graph search on a positive directed or undirected graph.
Array of positive distances. If vertex i is connected to vertex j, then dist_matrix[i,j] gives the distance between the vertices. If vertex i is not connected to vertex j, then dist_matrix[i,j] = 0
if True, then find the shortest path on a directed graph: only progress from a point to its neighbors, not the other way around. if False, then find the shortest path on an undirected graph: the algorithm can progress from a point to its neighbors and vice versa.
method to use. Options are ‘auto’ : attempt to choose the best method for the current problem ‘FW’ : Floyd-Warshall algorithm. O[N^3] ‘D’ : Dijkstra’s algorithm with Fibonacci stacks. O[(k+log(N))N^2]
G[i,j] gives the shortest distance from point i to point j along the graph.
As currently implemented, Dijkstra’s algorithm does not work for graphs with direction-dependent distances when directed == False. i.e., if dist_matrix[i,j] and dist_matrix[j,i] are not equal and both are nonzero, method=’D’ will not necessarily yield the correct result.
Also, these routines have not been tested for graphs with negative distances. Negative distances can lead to infinite cycles that must be handled by specialized algorithms.


Make arrays indexable for cross-validation.
Checks consistent length, passes through None, and ensures that everything can be indexed by converting sparse matrices to csr and converting non-interable objects to arrays.
List of objects to ensure sliceability.


Create a decorator for methods that are delegated to a sub-estimator
This enables ducktyping by hasattr returning True according to the sub-estimator.
Name of the sub-estimator that can be accessed as an attribute of the base object. If a list or a tuple of names are provided, the first sub-estimator that is an attribute of the base object will be used.
Inductive Clustering


Check if y is in a multilabel format.
Target values.
Return True, if y is in a multilabel format, else `False.


Determine the type of data indicated by the target.
Note that this type is the most specific type that can be inferred. For example:
One of:


Extract an ordered array of unique labels.
At the moment, we also don’t allow “multiclass-multioutput” input type.
An ordered array of unique labels.


Compute the 32bit murmurhash3 of key at seed.
The underlying implementation is MurmurHash3_x86_32 generating low latency 32bits hash suitable for implementing lookup tables, Bloom filters, count min sketch or feature hashing.
The physical object to hash.
Integer seed for the hashing algorithm.
from 0 to 2 ** 32 - 1
from -(2 ** 31) to 2 ** 31 - 1


Change the default backend used by Parallel inside a with block.
If backend is a string it must match a previously registered implementation using the register_parallel_backend function.
By default the following backends are available:
‘loky’ is recommended to run functions that manipulate Python objects. ‘threading’ is a low-overhead alternative that is most efficient for functions that release the Global Interpreter Lock: e.g. I/O-bound code or CPU-bound code in a few calls to native code that explicitly releases the GIL.
In addition, if the dask and distributed Python packages are installed, it is possible to use the ‘dask’ backend for better scheduling of nested parallel calls without over-subscription and potentially distribute parallel calls over a networked cluster of several hosts.
It is also possible to use the distributed ‘ray’ backend for distributing the workload to a cluster of nodes. To use the ‘ray’ joblib backend add the following lines:
Alternatively the backend can be passed directly as an instance.
By default all available workers will be used (n_jobs=-1) unless the caller passes an explicit value for the n_jobs parameter.
This is an alternative to passing a backend='backend_name' argument to the Parallel class constructor. It is particularly useful when calling into library code that uses joblib internally but does not expose the backend argument in its own API.
Warning: this function is experimental and subject to change in a future version of joblib.
Joblib also tries to limit the oversubscription by limiting the number of threads usable in some third-party library threadpools like OpenBLAS, MKL or OpenMP. The default limit in each worker is set to max(cpu_count() // effective_n_jobs, 1) but this limit can be overwritten with the inner_max_num_threads argument which will be used to set this limit in the child processes.
New in version 0.10.


Sample integers without replacement.
Select n_samples integers from the set [0, n_population) without replacement.
The size of the set to sample from.
The number of integer to sample.
If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.
If method == “auto”, the ratio of n_samples / n_population is used to determine which algorithm to use: If ratio is between 0 and 0.01, tracking selection is used. If ratio is between 0.01 and 0.99, numpy.random.permutation is used. If ratio is greater than 0.99, reservoir sampling is used. The order of the selected integers is undefined. If a random order is desired, the selected subset should be shuffled.
If method ==”tracking_selection”, a set based implementation is used which is suitable for n_samples <<< n_population.
If method == “reservoir_sampling”, a reservoir sampling algorithm is used which is suitable for high memory constraint or when O(n_samples) ~ O(n_population). The order of the selected integers is undefined. If a random order is desired, the selected subset should be shuffled.
If method == “pool”, a pool based algorithm is particularly fast, even faster than the tracking selection method. However, a vector containing the entire population has to be initialized. If n_samples ~ n_population, the reservoir sampling method is faster.
The sampled subsets of integer. The subset of selected integer might not be randomized, see the method argument.


Register a new Parallel backend factory.
The new backend can then be selected by passing its name as the backend argument to the Parallel class. Moreover, the default backend can be overwritten globally by setting make_default=True.
The factory can be any callable that takes no argument and return an instance of ParallelBackendBase.
Warning: this function is experimental and subject to change in a future version of joblib.
New in version 0.10.


Resample arrays or sparse matrices in a consistent way.
The default strategy implements one step of the bootstrapping procedure.
Indexable data-structures can be arrays, lists, dataframes or scipy sparse matrices with consistent first dimension.
Implements resampling with replacement. If False, this will implement (sliced) random permutations.
Number of samples to generate. If left to None this is automatically set to the first dimension of the arrays. If replace is False it should not be larger than the length of arrays.
Determines random number generation for shuffling the data. Pass an int for reproducible results across multiple function calls. See Glossary.
If not None, data is split in a stratified fashion, using this as the class labels.
Sequence of resampled copies of the collections. The original arrays are not impacted.
See also
It is possible to mix sparse and dense arrays in the same run:
Example using stratification:


Return a mask which is safe to use on X.
Data on which to apply mask.
Mask to be used on X.


Element wise squaring of array-likes and sparse matrices.
Whether to create a copy of X and operate on it or to perform inplace computation (default behaviour).


Shuffle arrays or sparse matrices in a consistent way.
This is a convenience alias to resample(*arrays, replace=False) to do random permutations of the collections.
Indexable data-structures can be arrays, lists, dataframes or scipy sparse matrices with consistent first dimension.
Determines random number generation for shuffling the data. Pass an int for reproducible results across multiple function calls. See Glossary.
Number of samples to generate. If left to None this is automatically set to the first dimension of the arrays. It should not be larger than the length of arrays.
Sequence of shuffled copies of the collections. The original arrays are not impacted.
See also
It is possible to mix sparse and dense arrays in the same run:
Color Quantization using K-Means
Empirical evaluation of the impact of k-means initialization
Combine predictors using stacking
Model Complexity Influence
Prediction Latency
Early stopping of Stochastic Gradient Descent
Approximate nearest neighbors in TSNE
Effect of varying threshold for self-training


Compute incremental mean and variance along an axis on a CSR or CSC matrix.
last_mean, last_var are the statistics computed at the last step by this function. Both must be initialized to 0-arrays of the proper size, i.e. the number of features in X. last_n is the number of samples encountered until now.
Input data.
Axis along which the axis should be computed.
Array of means to update with the new data X. Should be of shape (n_features,) if axis=0 or (n_samples,) if axis=1.
Array of variances to update with the new data X. Should be of shape (n_features,) if axis=0 or (n_samples,) if axis=1.
Sum of the weights seen so far, excluding the current weights If not float, it should be of shape (n_samples,) if axis=0 or (n_features,) if axis=1. If float it corresponds to having same weights for all samples (or features).
If axis is set to 0 shape is (n_samples,) or if axis is set to 1 shape is (n_features,). If it is set to None, then samples are equally weighted.
New in version 0.24.
Updated feature-wise means if axis = 0 or sample-wise means if axis = 1.
Updated feature-wise variances if axis = 0 or sample-wise variances if axis = 1.
Updated number of seen samples per feature if axis=0 or number of seen features per sample if axis=1.
If weights is not None, n is a sum of the weights of the seen samples or features instead of the actual number of seen samples or features.
NaNs are ignored in the algorithm.


Inplace column scaling of a CSC/CSR matrix.
Scale each feature of the data matrix by multiplying with specific scale provided by the caller assuming a (n_samples, n_features) shape.
Matrix to normalize using the variance of the features. It should be of CSC or CSR format.
Array of precomputed feature-wise values to use for scaling.


Inplace column scaling of a CSR matrix.
Scale each feature of the data matrix by multiplying with specific scale provided by the caller assuming a (n_samples, n_features) shape.
Matrix to normalize using the variance of the features. It should be of CSR format.
Array of precomputed feature-wise values to use for scaling.


Inplace row scaling of a CSR or CSC matrix.
Scale each row of the data matrix by multiplying with specific scale provided by the caller assuming a (n_samples, n_features) shape.
Matrix to be scaled. It should be of CSR or CSC format.
Array of precomputed sample-wise values to use for scaling.


Swaps two columns of a CSC/CSR matrix in-place.
Matrix whose two columns are to be swapped. It should be of CSR or CSC format.
Index of the column of X to be swapped.
Index of the column of X to be swapped.


Swaps two rows of a CSC/CSR matrix in-place.
Matrix whose two rows are to be swapped. It should be of CSR or CSC format.
Index of the row of X to be swapped.
Index of the row of X to be swapped.


Compute mean and variance along an axis on a CSR or CSC matrix.
Input data. It can be of CSR or CSC format.
Axis along which the axis should be computed.
if axis is set to 0 shape is (n_samples,) or if axis is set to 1 shape is (n_features,). If it is set to None, then samples are equally weighted.
New in version 0.24.
If True, returns the sum of weights seen for each feature if axis=0 or each sample if axis=1.
New in version 0.24.
Feature-wise means.
Feature-wise variances.
Returned if return_sum_weights is True.


Perform is_fitted validation for estimator.
Checks if the estimator is fitted by verifying the presence of fitted attributes (ending with a trailing underscore) and otherwise raises a NotFittedError with the given message.
This utility is meant to be used internally by estimators themselves, typically in their own predict / transform methods.
estimator instance for which the check is performed.
Attribute name(s) given as string or a list/tuple of strings Eg.: ["coef_", "estimator_", ...], "coef_"
If None, estimator is considered fitted if there exist an attribute that ends with a underscore and does not start with double underscore.
The default error message is, “This %(name)s instance is not fitted yet. Call ‘fit’ with appropriate arguments before using this estimator.”
For custom messages if “%(name)s” is present in the message string, it is substituted for the estimator name.
Eg. : “Estimator, %(name)s, must be fitted before sparsifying”.
Specify whether all or any of the given attributes must exist.
If the attributes are not found.


Check that memory is joblib.Memory-like.
joblib.Memory-like means that memory can be converted into a joblib.Memory instance (typically a str denoting the location) or has the same interface (has a cache method).
If memory is not joblib.Memory-like.


Make sure that array is 2D, square and symmetric.
If the array is not symmetric, then a symmetrized version is returned. Optionally, a warning or exception is raised if the matrix is not symmetric.
Input object to check / convert. Must be two-dimensional and square, otherwise a ValueError will be raised.
Absolute tolerance for equivalence of arrays. Default = 1E-10.
If True then raise a warning if conversion is required.
If True then raise an exception if array is not symmetric.
Symmetrized version of the input array, i.e. the average of array and array.transpose(). If sparse, then duplicate entries are first summed and zeros are eliminated.


Ravel column or 1d numpy array, else raises an error.
To control display of warnings.


Checks whether the estimator’s fit method supports the given parameter.
An estimator to inspect.
The searched parameter.
Whether the parameter was found to be a named parameter of the estimator’s fit method.


Return rows, items or columns of X using indices.
Warning
This utility is documented, but private. This means that backward compatibility might be broken without any deprecation cycle.
Data from which to sample rows, items or columns. list are only supported when axis=0.
The axis along which X will be subsampled. axis=0 will select rows while axis=1 will select columns.
Subset of X on axis 0 or 1.
CSR, CSC, and LIL sparse matrices are supported. COO sparse matrices are not supported.


Return the lowest bound for C such that for C in (l1_min_C, infinity) the model is guaranteed not to be empty. This applies to l1 penalized classifiers, such as LinearSVC with penalty=’l1’ and linear_model.LogisticRegression with penalty=’l1’.
This value is valid if class_weight parameter in fit() is not set.
Training vector, where n_samples in the number of samples and n_features is the number of features.
Target vector relative to X.
Specifies the loss function. With ‘squared_hinge’ it is the squared hinge loss (a.k.a. L2 loss). With ‘log’ it is the loss of logistic regression models.
Specifies if the intercept should be fitted by the model. It must match the fit() method parameter.
when fit_intercept is True, instance vector x becomes [x, intercept_scaling], i.e. a “synthetic” feature with constant value equals to intercept_scaling is appended to the instance vector. It must match the fit() method parameter.
minimum value for C


Linear Support Vector Classification.
Similar to SVC with parameter kernel=’linear’, but implemented in terms of liblinear rather than libsvm, so it has more flexibility in the choice of penalties and loss functions and should scale better to large numbers of samples.
This class supports both dense and sparse input and the multiclass support is handled according to a one-vs-the-rest scheme.
Read more in the User Guide.
Specifies the norm used in the penalization. The ‘l2’ penalty is the standard used in SVC. The ‘l1’ leads to coef_ vectors that are sparse.
Specifies the loss function. ‘hinge’ is the standard SVM loss (used e.g. by the SVC class) while ‘squared_hinge’ is the square of the hinge loss. The combination of penalty='l1' and loss='hinge' is not supported.
Select the algorithm to either solve the dual or primal optimization problem. Prefer dual=False when n_samples > n_features.
Tolerance for stopping criteria.
Regularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive.
Determines the multi-class strategy if y contains more than two classes. "ovr" trains n_classes one-vs-rest classifiers, while "crammer_singer" optimizes a joint objective over all classes. While crammer_singer is interesting from a theoretical perspective as it is consistent, it is seldom used in practice as it rarely leads to better accuracy and is more expensive to compute. If "crammer_singer" is chosen, the options loss, penalty and dual will be ignored.
Whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (i.e. data is expected to be already centered).
When self.fit_intercept is True, instance vector x becomes [x, self.intercept_scaling], i.e. a “synthetic” feature with constant value equals to intercept_scaling is appended to the instance vector. The intercept becomes intercept_scaling * synthetic feature weight Note! the synthetic feature weight is subject to l1/l2 regularization as all other features. To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased.
Set the parameter C of class i to class_weight[i]*C for SVC. If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y)).
Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in liblinear that, if enabled, may not work properly in a multithreaded context.
Controls the pseudo random number generation for shuffling the data for the dual coordinate descent (if dual=True). When dual=False the underlying implementation of LinearSVC is not random and random_state has no effect on the results. Pass an int for reproducible output across multiple function calls. See Glossary.
The maximum number of iterations to be run.
Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel.
coef_ is a readonly property derived from raw_coef_ that follows the internal memory layout of liblinear.
Constants in decision function.
The unique classes labels.
Maximum number of iterations run across all classes.
See also
Implementation of Support Vector Machine classifier using libsvm: the kernel can be non-linear but its SMO algorithm does not scale to large number of samples as LinearSVC does. Furthermore SVC multi-class mode is implemented using one vs one scheme while LinearSVC uses one vs the rest. It is possible to implement one vs the rest with SVC by using the OneVsRestClassifier wrapper. Finally SVC can fit dense data without memory copy if the input is C-contiguous. Sparse data will still incur memory copy though.
SGDClassifier can optimize the same cost function as LinearSVC by adjusting the penalty and loss parameters. In addition it requires less memory, allows incremental (online) learning, and implements various loss functions and regularization regimes.
The underlying C implementation uses a random number generator to select features when fitting the model. It is thus not uncommon to have slightly different results for the same input data. If that happens, try with a smaller tol parameter.
The underlying implementation, liblinear, uses a sparse internal representation for the data that will incur a memory copy.
Predict output may not match that of standalone liblinear in certain cases. See differences from liblinear in the narrative documentation.
LIBLINEAR: A Library for Large Linear Classification
decision_function(X)
Predict confidence scores for samples.
densify()
Convert coefficient matrix to dense array format.
fit(X, y[, sample_weight])
Fit the model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict class labels for samples in X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
sparsify()
Convert coefficient matrix to sparse format.
Predict confidence scores for samples.
The confidence score for a sample is proportional to the signed distance of that sample to the hyperplane.
Samples.
Confidence scores per (sample, class) combination. In the binary case, confidence score for self.classes_[1] where >0 means this class would be predicted.
Convert coefficient matrix to dense array format.
Converts the coef_ member (back) to a numpy.ndarray. This is the default format of coef_ and is required for fitting, so calling this method is only required on models that have previously been sparsified; otherwise, it is a no-op.
Fitted estimator.
Fit the model according to the given training data.
Training vector, where n_samples in the number of samples and n_features is the number of features.
Target vector relative to X.
Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
New in version 0.18.
An instance of the estimator.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict class labels for samples in X.
Samples.
Predicted class label per sample.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Convert coefficient matrix to sparse format.
Converts the coef_ member to a scipy.sparse matrix, which for L1-regularized models can be much more memory- and storage-efficient than the usual numpy.ndarray representation.
The intercept_ member is not converted.
Fitted estimator.
For non-sparse models, i.e. when there are not many zeros in coef_, this may actually increase memory usage, so use this method with care. A rule of thumb is that the number of zero elements, which can be computed with (coef_ == 0).sum(), must be more than 50% for this to provide significant benefits.
After calling this method, further fitting with the partial_fit method (if any) will not work until you call densify.


Linear Support Vector Classification.
Similar to SVC with parameter kernel=’linear’, but implemented in terms of liblinear rather than libsvm, so it has more flexibility in the choice of penalties and loss functions and should scale better to large numbers of samples.
This class supports both dense and sparse input and the multiclass support is handled according to a one-vs-the-rest scheme.
Read more in the User Guide.
Specifies the norm used in the penalization. The ‘l2’ penalty is the standard used in SVC. The ‘l1’ leads to coef_ vectors that are sparse.
Specifies the loss function. ‘hinge’ is the standard SVM loss (used e.g. by the SVC class) while ‘squared_hinge’ is the square of the hinge loss. The combination of penalty='l1' and loss='hinge' is not supported.
Select the algorithm to either solve the dual or primal optimization problem. Prefer dual=False when n_samples > n_features.
Tolerance for stopping criteria.
Regularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive.
Determines the multi-class strategy if y contains more than two classes. "ovr" trains n_classes one-vs-rest classifiers, while "crammer_singer" optimizes a joint objective over all classes. While crammer_singer is interesting from a theoretical perspective as it is consistent, it is seldom used in practice as it rarely leads to better accuracy and is more expensive to compute. If "crammer_singer" is chosen, the options loss, penalty and dual will be ignored.
Whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (i.e. data is expected to be already centered).
When self.fit_intercept is True, instance vector x becomes [x, self.intercept_scaling], i.e. a “synthetic” feature with constant value equals to intercept_scaling is appended to the instance vector. The intercept becomes intercept_scaling * synthetic feature weight Note! the synthetic feature weight is subject to l1/l2 regularization as all other features. To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased.
Set the parameter C of class i to class_weight[i]*C for SVC. If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y)).
Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in liblinear that, if enabled, may not work properly in a multithreaded context.
Controls the pseudo random number generation for shuffling the data for the dual coordinate descent (if dual=True). When dual=False the underlying implementation of LinearSVC is not random and random_state has no effect on the results. Pass an int for reproducible output across multiple function calls. See Glossary.
The maximum number of iterations to be run.
Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel.
coef_ is a readonly property derived from raw_coef_ that follows the internal memory layout of liblinear.
Constants in decision function.
The unique classes labels.
Maximum number of iterations run across all classes.
See also
Implementation of Support Vector Machine classifier using libsvm: the kernel can be non-linear but its SMO algorithm does not scale to large number of samples as LinearSVC does. Furthermore SVC multi-class mode is implemented using one vs one scheme while LinearSVC uses one vs the rest. It is possible to implement one vs the rest with SVC by using the OneVsRestClassifier wrapper. Finally SVC can fit dense data without memory copy if the input is C-contiguous. Sparse data will still incur memory copy though.
SGDClassifier can optimize the same cost function as LinearSVC by adjusting the penalty and loss parameters. In addition it requires less memory, allows incremental (online) learning, and implements various loss functions and regularization regimes.
The underlying C implementation uses a random number generator to select features when fitting the model. It is thus not uncommon to have slightly different results for the same input data. If that happens, try with a smaller tol parameter.
The underlying implementation, liblinear, uses a sparse internal representation for the data that will incur a memory copy.
Predict output may not match that of standalone liblinear in certain cases. See differences from liblinear in the narrative documentation.
LIBLINEAR: A Library for Large Linear Classification
decision_function(X)
Predict confidence scores for samples.
densify()
Convert coefficient matrix to dense array format.
fit(X, y[, sample_weight])
Fit the model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict class labels for samples in X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
sparsify()
Convert coefficient matrix to sparse format.
Predict confidence scores for samples.
The confidence score for a sample is proportional to the signed distance of that sample to the hyperplane.
Samples.
Confidence scores per (sample, class) combination. In the binary case, confidence score for self.classes_[1] where >0 means this class would be predicted.
Convert coefficient matrix to dense array format.
Converts the coef_ member (back) to a numpy.ndarray. This is the default format of coef_ and is required for fitting, so calling this method is only required on models that have previously been sparsified; otherwise, it is a no-op.
Fitted estimator.
Fit the model according to the given training data.
Training vector, where n_samples in the number of samples and n_features is the number of features.
Target vector relative to X.
Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
New in version 0.18.
An instance of the estimator.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict class labels for samples in X.
Samples.
Predicted class label per sample.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Convert coefficient matrix to sparse format.
Converts the coef_ member to a scipy.sparse matrix, which for L1-regularized models can be much more memory- and storage-efficient than the usual numpy.ndarray representation.
The intercept_ member is not converted.
Fitted estimator.
For non-sparse models, i.e. when there are not many zeros in coef_, this may actually increase memory usage, so use this method with care. A rule of thumb is that the number of zero elements, which can be computed with (coef_ == 0).sum(), must be more than 50% for this to provide significant benefits.
After calling this method, further fitting with the partial_fit method (if any) will not work until you call densify.
Release Highlights for scikit-learn 0.22
Comparison of Calibration of Classifiers
Probability Calibration curves
Pipeline Anova SVM
Univariate Feature Selection
Scalable learning with polynomial kernel aproximation
Explicit feature map approximation for RBF kernels
Detection error tradeoff (DET) curve
Balance model complexity and cross-validated score
Precision-Recall
Selecting dimensionality reduction with Pipeline and GridSearchCV
Column Transformer with Heterogeneous Data Sources
Feature discretization
Plot the support vectors in LinearSVC
Plot different SVM classifiers in the iris dataset
Scaling the regularization parameter for SVCs
Classification of text documents using sparse features


Predict confidence scores for samples.
The confidence score for a sample is proportional to the signed distance of that sample to the hyperplane.
Samples.
Confidence scores per (sample, class) combination. In the binary case, confidence score for self.classes_[1] where >0 means this class would be predicted.


Convert coefficient matrix to dense array format.
Converts the coef_ member (back) to a numpy.ndarray. This is the default format of coef_ and is required for fitting, so calling this method is only required on models that have previously been sparsified; otherwise, it is a no-op.
Fitted estimator.


Fit the model according to the given training data.
Training vector, where n_samples in the number of samples and n_features is the number of features.
Target vector relative to X.
Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
New in version 0.18.
An instance of the estimator.


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Predict class labels for samples in X.
Samples.
Predicted class label per sample.


Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Convert coefficient matrix to sparse format.
Converts the coef_ member to a scipy.sparse matrix, which for L1-regularized models can be much more memory- and storage-efficient than the usual numpy.ndarray representation.
The intercept_ member is not converted.
Fitted estimator.
For non-sparse models, i.e. when there are not many zeros in coef_, this may actually increase memory usage, so use this method with care. A rule of thumb is that the number of zero elements, which can be computed with (coef_ == 0).sum(), must be more than 50% for this to provide significant benefits.
After calling this method, further fitting with the partial_fit method (if any) will not work until you call densify.


Linear Support Vector Regression.
Similar to SVR with parameter kernel=’linear’, but implemented in terms of liblinear rather than libsvm, so it has more flexibility in the choice of penalties and loss functions and should scale better to large numbers of samples.
This class supports both dense and sparse input.
Read more in the User Guide.
New in version 0.16.
Epsilon parameter in the epsilon-insensitive loss function. Note that the value of this parameter depends on the scale of the target variable y. If unsure, set epsilon=0.
Tolerance for stopping criteria.
Regularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive.
Specifies the loss function. The epsilon-insensitive loss (standard SVR) is the L1 loss, while the squared epsilon-insensitive loss (‘squared_epsilon_insensitive’) is the L2 loss.
Whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (i.e. data is expected to be already centered).
When self.fit_intercept is True, instance vector x becomes [x, self.intercept_scaling], i.e. a “synthetic” feature with constant value equals to intercept_scaling is appended to the instance vector. The intercept becomes intercept_scaling * synthetic feature weight Note! the synthetic feature weight is subject to l1/l2 regularization as all other features. To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased.
Select the algorithm to either solve the dual or primal optimization problem. Prefer dual=False when n_samples > n_features.
Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in liblinear that, if enabled, may not work properly in a multithreaded context.
Controls the pseudo random number generation for shuffling the data. Pass an int for reproducible output across multiple function calls. See Glossary.
The maximum number of iterations to be run.
Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel.
coef_ is a readonly property derived from raw_coef_ that follows the internal memory layout of liblinear.
Constants in decision function.
Maximum number of iterations run across all classes.
See also
Implementation of Support Vector Machine classifier using the same library as this class (liblinear).
Implementation of Support Vector Machine regression using libsvm: the kernel can be non-linear but its SMO algorithm does not scale to large number of samples as LinearSVC does.
SGDRegressor can optimize the same cost function as LinearSVR by adjusting the penalty and loss parameters. In addition it requires less memory, allows incremental (online) learning, and implements various loss functions and regularization regimes.
fit(X, y[, sample_weight])
Fit the model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict using the linear model.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit the model according to the given training data.
Training vector, where n_samples in the number of samples and n_features is the number of features.
Target vector relative to X
Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
New in version 0.18.
An instance of the estimator.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict using the linear model.
Samples.
Returns predicted values.
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Fit the model according to the given training data.
Training vector, where n_samples in the number of samples and n_features is the number of features.
Target vector relative to X
Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
New in version 0.18.
An instance of the estimator.


Predict using the linear model.
Samples.
Returns predicted values.


Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).


Nu-Support Vector Classification.
Similar to SVC but uses a parameter to control the number of support vectors.
The implementation is based on libsvm.
Read more in the User Guide.
An upper bound on the fraction of margin errors (see User Guide) and a lower bound of the fraction of support vectors. Should be in the interval (0, 1].
Specifies the kernel type to be used in the algorithm. It must be one of ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’ or a callable. If none is given, ‘rbf’ will be used. If a callable is given it is used to precompute the kernel matrix.
Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels.
Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’.
Changed in version 0.22: The default value of gamma changed from ‘auto’ to ‘scale’.
Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’.
Whether to use the shrinking heuristic. See the User Guide.
Whether to enable probability estimates. This must be enabled prior to calling fit, will slow down that method as it internally uses 5-fold cross-validation, and predict_proba may be inconsistent with predict. Read more in the User Guide.
Tolerance for stopping criterion.
Specify the size of the kernel cache (in MB).
Set the parameter C of class i to class_weight[i]*C for SVC. If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies as n_samples / (n_classes * np.bincount(y))
Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in libsvm that, if enabled, may not work properly in a multithreaded context.
Hard limit on iterations within solver, or -1 for no limit.
Whether to return a one-vs-rest (‘ovr’) decision function of shape (n_samples, n_classes) as all other classifiers, or the original one-vs-one (‘ovo’) decision function of libsvm which has shape (n_samples, n_classes * (n_classes - 1) / 2). However, one-vs-one (‘ovo’) is always used as multi-class strategy. The parameter is ignored for binary classification.
Changed in version 0.19: decision_function_shape is ‘ovr’ by default.
New in version 0.17: decision_function_shape=’ovr’ is recommended.
Changed in version 0.17: Deprecated decision_function_shape=’ovo’ and None.
If true, decision_function_shape='ovr', and number of classes > 2, predict will break ties according to the confidence values of decision_function; otherwise the first class among the tied classes is returned. Please note that breaking ties comes at a relatively high computational cost compared to a simple predict.
New in version 0.22.
Controls the pseudo random number generation for shuffling the data for probability estimates. Ignored when probability is False. Pass an int for reproducible output across multiple function calls. See Glossary.
Multipliers of parameter C of each class. Computed based on the class_weight parameter.
The unique classes labels.
Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel.
coef_ is readonly property derived from dual_coef_ and support_vectors_.
Dual coefficients of the support vector in the decision function (see Mathematical formulation), multiplied by their targets. For multiclass, coefficient for all 1-vs-1 classifiers. The layout of the coefficients in the multiclass case is somewhat non-trivial. See the multi-class section of the User Guide for details.
0 if correctly fitted, 1 if the algorithm did not converge.
Constants in decision function.
Indices of support vectors.
Support vectors.
Number of support vectors for each class.
0 if correctly fitted, 1 if the algorithm did not converge.
If probability=True, it corresponds to the parameters learned in Platt scaling to produce probability estimates from decision values. If probability=False, it’s an empty array. Platt scaling uses the logistic function 1 / (1 + exp(decision_value * probA_ + probB_)) where probA_ and probB_ are learned from the dataset [2]. For more information on the multiclass case and training procedure see section 8 of [1].
Array dimensions of training vector X.
See also
Support Vector Machine for classification using libsvm.
Scalable linear Support Vector Machine for classification using liblinear.
LIBSVM: A Library for Support Vector Machines
Platt, John (1999). “Probabilistic outputs for support vector machines and comparison to regularizedlikelihood methods.”
decision_function(X)
Evaluates the decision function for the samples in X.
fit(X, y[, sample_weight])
Fit the SVM model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Perform classification on samples in X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Evaluates the decision function for the samples in X.
Returns the decision function of the sample for each class in the model. If decision_function_shape=’ovr’, the shape is (n_samples, n_classes).
If decision_function_shape=’ovo’, the function values are proportional to the distance of the samples X to the separating hyperplane. If the exact distances are required, divide the function values by the norm of the weight vector (coef_). See also this question for further details. If decision_function_shape=’ovr’, the decision function is a monotonic transformation of ovo decision function.
Fit the SVM model according to the given training data.
Training vectors, where n_samples is the number of samples and n_features is the number of features. For kernel=”precomputed”, the expected shape of X is (n_samples, n_samples).
Target values (class labels in classification, real numbers in regression).
Per-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points.
If X and y are not C-ordered and contiguous arrays of np.float64 and X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
If X is a dense array, then the other methods will not support sparse matrices as input.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Perform classification on samples in X.
For an one-class model, +1 or -1 is returned.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Class labels for samples in X.
Compute log probabilities of possible outcomes for samples in X.
The model need to have probability information computed at training time: fit with attribute probability set to True.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Returns the log-probabilities of the sample for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
The probability model is created using cross validation, so the results can be slightly different than those obtained by predict. Also, it will produce meaningless results on very small datasets.
Compute probabilities of possible outcomes for samples in X.
The model need to have probability information computed at training time: fit with attribute probability set to True.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Returns the probability of the sample for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
The probability model is created using cross validation, so the results can be slightly different than those obtained by predict. Also, it will produce meaningless results on very small datasets.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Nu-Support Vector Classification.
Similar to SVC but uses a parameter to control the number of support vectors.
The implementation is based on libsvm.
Read more in the User Guide.
An upper bound on the fraction of margin errors (see User Guide) and a lower bound of the fraction of support vectors. Should be in the interval (0, 1].
Specifies the kernel type to be used in the algorithm. It must be one of ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’ or a callable. If none is given, ‘rbf’ will be used. If a callable is given it is used to precompute the kernel matrix.
Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels.
Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’.
Changed in version 0.22: The default value of gamma changed from ‘auto’ to ‘scale’.
Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’.
Whether to use the shrinking heuristic. See the User Guide.
Whether to enable probability estimates. This must be enabled prior to calling fit, will slow down that method as it internally uses 5-fold cross-validation, and predict_proba may be inconsistent with predict. Read more in the User Guide.
Tolerance for stopping criterion.
Specify the size of the kernel cache (in MB).
Set the parameter C of class i to class_weight[i]*C for SVC. If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies as n_samples / (n_classes * np.bincount(y))
Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in libsvm that, if enabled, may not work properly in a multithreaded context.
Hard limit on iterations within solver, or -1 for no limit.
Whether to return a one-vs-rest (‘ovr’) decision function of shape (n_samples, n_classes) as all other classifiers, or the original one-vs-one (‘ovo’) decision function of libsvm which has shape (n_samples, n_classes * (n_classes - 1) / 2). However, one-vs-one (‘ovo’) is always used as multi-class strategy. The parameter is ignored for binary classification.
Changed in version 0.19: decision_function_shape is ‘ovr’ by default.
New in version 0.17: decision_function_shape=’ovr’ is recommended.
Changed in version 0.17: Deprecated decision_function_shape=’ovo’ and None.
If true, decision_function_shape='ovr', and number of classes > 2, predict will break ties according to the confidence values of decision_function; otherwise the first class among the tied classes is returned. Please note that breaking ties comes at a relatively high computational cost compared to a simple predict.
New in version 0.22.
Controls the pseudo random number generation for shuffling the data for probability estimates. Ignored when probability is False. Pass an int for reproducible output across multiple function calls. See Glossary.
Multipliers of parameter C of each class. Computed based on the class_weight parameter.
The unique classes labels.
Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel.
coef_ is readonly property derived from dual_coef_ and support_vectors_.
Dual coefficients of the support vector in the decision function (see Mathematical formulation), multiplied by their targets. For multiclass, coefficient for all 1-vs-1 classifiers. The layout of the coefficients in the multiclass case is somewhat non-trivial. See the multi-class section of the User Guide for details.
0 if correctly fitted, 1 if the algorithm did not converge.
Constants in decision function.
Indices of support vectors.
Support vectors.
Number of support vectors for each class.
0 if correctly fitted, 1 if the algorithm did not converge.
If probability=True, it corresponds to the parameters learned in Platt scaling to produce probability estimates from decision values. If probability=False, it’s an empty array. Platt scaling uses the logistic function 1 / (1 + exp(decision_value * probA_ + probB_)) where probA_ and probB_ are learned from the dataset [2]. For more information on the multiclass case and training procedure see section 8 of [1].
Array dimensions of training vector X.
See also
Support Vector Machine for classification using libsvm.
Scalable linear Support Vector Machine for classification using liblinear.
LIBSVM: A Library for Support Vector Machines
Platt, John (1999). “Probabilistic outputs for support vector machines and comparison to regularizedlikelihood methods.”
decision_function(X)
Evaluates the decision function for the samples in X.
fit(X, y[, sample_weight])
Fit the SVM model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Perform classification on samples in X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Evaluates the decision function for the samples in X.
Returns the decision function of the sample for each class in the model. If decision_function_shape=’ovr’, the shape is (n_samples, n_classes).
If decision_function_shape=’ovo’, the function values are proportional to the distance of the samples X to the separating hyperplane. If the exact distances are required, divide the function values by the norm of the weight vector (coef_). See also this question for further details. If decision_function_shape=’ovr’, the decision function is a monotonic transformation of ovo decision function.
Fit the SVM model according to the given training data.
Training vectors, where n_samples is the number of samples and n_features is the number of features. For kernel=”precomputed”, the expected shape of X is (n_samples, n_samples).
Target values (class labels in classification, real numbers in regression).
Per-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points.
If X and y are not C-ordered and contiguous arrays of np.float64 and X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
If X is a dense array, then the other methods will not support sparse matrices as input.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Perform classification on samples in X.
For an one-class model, +1 or -1 is returned.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Class labels for samples in X.
Compute log probabilities of possible outcomes for samples in X.
The model need to have probability information computed at training time: fit with attribute probability set to True.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Returns the log-probabilities of the sample for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
The probability model is created using cross validation, so the results can be slightly different than those obtained by predict. Also, it will produce meaningless results on very small datasets.
Compute probabilities of possible outcomes for samples in X.
The model need to have probability information computed at training time: fit with attribute probability set to True.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Returns the probability of the sample for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
The probability model is created using cross validation, so the results can be slightly different than those obtained by predict. Also, it will produce meaningless results on very small datasets.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Non-linear SVM


Evaluates the decision function for the samples in X.
Returns the decision function of the sample for each class in the model. If decision_function_shape=’ovr’, the shape is (n_samples, n_classes).
If decision_function_shape=’ovo’, the function values are proportional to the distance of the samples X to the separating hyperplane. If the exact distances are required, divide the function values by the norm of the weight vector (coef_). See also this question for further details. If decision_function_shape=’ovr’, the decision function is a monotonic transformation of ovo decision function.


Fit the SVM model according to the given training data.
Training vectors, where n_samples is the number of samples and n_features is the number of features. For kernel=”precomputed”, the expected shape of X is (n_samples, n_samples).
Target values (class labels in classification, real numbers in regression).
Per-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points.
If X and y are not C-ordered and contiguous arrays of np.float64 and X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
If X is a dense array, then the other methods will not support sparse matrices as input.


Perform classification on samples in X.
For an one-class model, +1 or -1 is returned.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Class labels for samples in X.


Compute log probabilities of possible outcomes for samples in X.
The model need to have probability information computed at training time: fit with attribute probability set to True.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Returns the log-probabilities of the sample for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
The probability model is created using cross validation, so the results can be slightly different than those obtained by predict. Also, it will produce meaningless results on very small datasets.


Compute probabilities of possible outcomes for samples in X.
The model need to have probability information computed at training time: fit with attribute probability set to True.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Returns the probability of the sample for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
The probability model is created using cross validation, so the results can be slightly different than those obtained by predict. Also, it will produce meaningless results on very small datasets.


Nu Support Vector Regression.
Similar to NuSVC, for regression, uses a parameter nu to control the number of support vectors. However, unlike NuSVC, where nu replaces C, here nu replaces the parameter epsilon of epsilon-SVR.
The implementation is based on libsvm.
Read more in the User Guide.
An upper bound on the fraction of training errors and a lower bound of the fraction of support vectors. Should be in the interval (0, 1]. By default 0.5 will be taken.
Penalty parameter C of the error term.
Specifies the kernel type to be used in the algorithm. It must be one of ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’ or a callable. If none is given, ‘rbf’ will be used. If a callable is given it is used to precompute the kernel matrix.
Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels.
Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’.
Changed in version 0.22: The default value of gamma changed from ‘auto’ to ‘scale’.
Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’.
Whether to use the shrinking heuristic. See the User Guide.
Tolerance for stopping criterion.
Specify the size of the kernel cache (in MB).
Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in libsvm that, if enabled, may not work properly in a multithreaded context.
Hard limit on iterations within solver, or -1 for no limit.
Multipliers of parameter C for each class. Computed based on the class_weight parameter.
Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel.
coef_ is readonly property derived from dual_coef_ and support_vectors_.
Coefficients of the support vector in the decision function.
0 if correctly fitted, 1 otherwise (will raise warning)
Constants in decision function.
Number of support vectors for each class.
Array dimensions of training vector X.
Indices of support vectors.
Support vectors.
See also
Support Vector Machine for classification implemented with libsvm with a parameter to control the number of support vectors.
Epsilon Support Vector Machine for regression implemented with libsvm.
LIBSVM: A Library for Support Vector Machines
Platt, John (1999). “Probabilistic outputs for support vector machines and comparison to regularizedlikelihood methods.”
fit(X, y[, sample_weight])
Fit the SVM model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Perform regression on samples in X.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit the SVM model according to the given training data.
Training vectors, where n_samples is the number of samples and n_features is the number of features. For kernel=”precomputed”, the expected shape of X is (n_samples, n_samples).
Target values (class labels in classification, real numbers in regression).
Per-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points.
If X and y are not C-ordered and contiguous arrays of np.float64 and X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
If X is a dense array, then the other methods will not support sparse matrices as input.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Perform regression on samples in X.
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Nu Support Vector Regression.
Similar to NuSVC, for regression, uses a parameter nu to control the number of support vectors. However, unlike NuSVC, where nu replaces C, here nu replaces the parameter epsilon of epsilon-SVR.
The implementation is based on libsvm.
Read more in the User Guide.
An upper bound on the fraction of training errors and a lower bound of the fraction of support vectors. Should be in the interval (0, 1]. By default 0.5 will be taken.
Penalty parameter C of the error term.
Specifies the kernel type to be used in the algorithm. It must be one of ‘linear’, ‘poly’, ‘rbf’, ‘sigmoid’, ‘precomputed’ or a callable. If none is given, ‘rbf’ will be used. If a callable is given it is used to precompute the kernel matrix.
Degree of the polynomial kernel function (‘poly’). Ignored by all other kernels.
Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’.
Changed in version 0.22: The default value of gamma changed from ‘auto’ to ‘scale’.
Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’.
Whether to use the shrinking heuristic. See the User Guide.
Tolerance for stopping criterion.
Specify the size of the kernel cache (in MB).
Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in libsvm that, if enabled, may not work properly in a multithreaded context.
Hard limit on iterations within solver, or -1 for no limit.
Multipliers of parameter C for each class. Computed based on the class_weight parameter.
Weights assigned to the features (coefficients in the primal problem). This is only available in the case of a linear kernel.
coef_ is readonly property derived from dual_coef_ and support_vectors_.
Coefficients of the support vector in the decision function.
0 if correctly fitted, 1 otherwise (will raise warning)
Constants in decision function.
Number of support vectors for each class.
Array dimensions of training vector X.
Indices of support vectors.
Support vectors.
See also
Support Vector Machine for classification implemented with libsvm with a parameter to control the number of support vectors.
Epsilon Support Vector Machine for regression implemented with libsvm.
LIBSVM: A Library for Support Vector Machines
Platt, John (1999). “Probabilistic outputs for support vector machines and comparison to regularizedlikelihood methods.”
fit(X, y[, sample_weight])
Fit the SVM model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Perform regression on samples in X.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit the SVM model according to the given training data.
Training vectors, where n_samples is the number of samples and n_features is the number of features. For kernel=”precomputed”, the expected shape of X is (n_samples, n_samples).
Target values (class labels in classification, real numbers in regression).
Per-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points.
If X and y are not C-ordered and contiguous arrays of np.float64 and X is not a scipy.sparse.csr_matrix, X and/or y may be copied.
If X is a dense array, then the other methods will not support sparse matrices as input.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Perform regression on samples in X.
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Model Complexity Influence


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Perform regression on samples in X.
For an one-class model, +1 (inlier) or -1 (outlier) is returned.
For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.