package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
val get_py : string -> Py.Object.t

Get an attribute of this module as a Py.Object.t. This is useful to pass a Python function to another function.

module Chain : sig ... end
module Dok_matrix : sig ... end
module Lil_matrix : sig ... end
module Spmatrix : sig ... end
val check_array : ?accept_sparse:[ `StringList of string list | `S of string | `Bool of bool ] -> ?accept_large_sparse:bool -> ?dtype: [ `S of string | `Dtype of Np.Dtype.t | `Dtypes of Np.Dtype.t list | `None ] -> ?order:[ `F | `C ] -> ?copy:bool -> ?force_all_finite:[ `Allow_nan | `Bool of bool ] -> ?ensure_2d:bool -> ?allow_nd:bool -> ?ensure_min_samples:int -> ?ensure_min_features:int -> ?warn_on_dtype:bool -> ?estimator:[> `BaseEstimator ] Np.Obj.t -> array:Py.Object.t -> unit -> Py.Object.t

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.

Parameters ---------- array : object Input object to check / convert.

accept_sparse : string, boolean or list/tuple of strings (default=False) Strings 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.

accept_large_sparse : bool (default=True) 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.

.. versionadded:: 0.20

dtype : string, type, list of types or None (default='numeric') 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.

order : 'F', 'C' or None (default=None) 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.

copy : boolean (default=False) Whether a forced copy will be triggered. If copy=False, a copy might be triggered by a conversion.

force_all_finite : boolean or 'allow-nan', (default=True) Whether to raise an error on np.inf and np.nan in array. The possibilities are:

  • True: Force all values of array to be finite.
  • False: accept both np.inf and np.nan in array.
  • 'allow-nan': accept only np.nan values in array. Values cannot be infinite.

For object dtyped data, only np.nan is checked and not np.inf.

.. versionadded:: 0.20 ``force_all_finite`` accepts the string ``'allow-nan'``.

ensure_2d : boolean (default=True) Whether to raise a value error if array is not 2D.

allow_nd : boolean (default=False) Whether to allow array.ndim > 2.

ensure_min_samples : int (default=1) 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.

ensure_min_features : int (default=1) 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.

warn_on_dtype : boolean or None, optional (default=None) Raise DataConversionWarning if the dtype of the input data structure does not match the requested dtype, causing a memory copy.

.. deprecated:: 0.21 ``warn_on_dtype`` is deprecated in version 0.21 and will be removed in 0.23.

estimator : str or estimator instance (default=None) If passed, include the name of the estimator in warning messages.

Returns ------- array_converted : object The converted and validated array.

val check_classification_targets : [> `ArrayLike ] Np.Obj.t -> Py.Object.t

Ensure that target y is of a non-regression type.

Only the following target types (as defined in type_of_target) are allowed: 'binary', 'multiclass', 'multiclass-multioutput', 'multilabel-indicator', 'multilabel-sequences'

Parameters ---------- y : array-like

val class_distribution : ?sample_weight:[> `ArrayLike ] Np.Obj.t -> y: [ `Arr of [> `ArrayLike ] Np.Obj.t | `Sparse_matrix_of_size of Py.Object.t ] -> unit -> Py.Object.t * Py.Object.t * Py.Object.t

Compute class priors from multioutput-multiclass target data

Parameters ---------- y : array like or sparse matrix of size (n_samples, n_outputs) The labels for each example.

sample_weight : array-like of shape (n_samples,), default=None Sample weights.

Returns ------- classes : list of size n_outputs of arrays of size (n_classes,) List of classes for each column.

n_classes : list of integers of size n_outputs Number of classes in each column

class_prior : list of size n_outputs of arrays of size (n_classes,) Class distribution of each column.

val is_multilabel : [> `ArrayLike ] Np.Obj.t -> bool

Check if ``y`` is in a multilabel format.

Parameters ---------- y : numpy array of shape n_samples Target values.

Returns ------- out : bool, Return ``True``, if ``y`` is in a multilabel format, else ```False``.

Examples -------- >>> import numpy as np >>> from sklearn.utils.multiclass import is_multilabel >>> is_multilabel(0, 1, 0, 1) False >>> is_multilabel([1], [0, 2], []) False >>> is_multilabel(np.array([1, 0], [0, 0])) True >>> is_multilabel(np.array([1], [0], [0])) False >>> is_multilabel(np.array([1, 0, 0])) True

val issparse : Py.Object.t -> Py.Object.t

Is x of a sparse matrix type?

Parameters ---------- x object to check for being a sparse matrix

Returns ------- bool True if x is a sparse matrix, False otherwise

Notes ----- issparse and isspmatrix are aliases for the same function.

Examples -------- >>> from scipy.sparse import csr_matrix, isspmatrix >>> isspmatrix(csr_matrix([5])) True

>>> from scipy.sparse import isspmatrix >>> isspmatrix(5) False

val type_of_target : [> `ArrayLike ] Np.Obj.t -> string

Determine the type of data indicated by the target.

Note that this type is the most specific type that can be inferred. For example:

* ``binary`` is more specific but compatible with ``multiclass``. * ``multiclass`` of integers is more specific but compatible with ``continuous``. * ``multilabel-indicator`` is more specific but compatible with ``multiclass-multioutput``.

Parameters ---------- y : array-like

Returns ------- target_type : string One of:

* 'continuous': `y` is an array-like of floats that are not all integers, and is 1d or a column vector. * 'continuous-multioutput': `y` is a 2d array of floats that are not all integers, and both dimensions are of size > 1. * 'binary': `y` contains <= 2 discrete values and is 1d or a column vector. * 'multiclass': `y` contains more than two discrete values, is not a sequence of sequences, and is 1d or a column vector. * 'multiclass-multioutput': `y` is a 2d array that contains more than two discrete values, is not a sequence of sequences, and both dimensions are of size > 1. * 'multilabel-indicator': `y` is a label indicator matrix, an array of two dimensions with at least two columns, and at most 2 unique values. * 'unknown': `y` is array-like but none of the above, such as a 3d array, sequence of sequences, or an array of non-sequence objects.

Examples -------- >>> import numpy as np >>> type_of_target(0.1, 0.6) 'continuous' >>> type_of_target(1, -1, -1, 1) 'binary' >>> type_of_target('a', 'b', 'a') 'binary' >>> type_of_target(1.0, 2.0) 'binary' >>> type_of_target(1, 0, 2) 'multiclass' >>> type_of_target(1.0, 0.0, 3.0) 'multiclass' >>> type_of_target('a', 'b', 'c') 'multiclass' >>> type_of_target(np.array([1, 2], [3, 1])) 'multiclass-multioutput' >>> type_of_target([1, 2]) 'multilabel-indicator' >>> type_of_target(np.array([1.5, 2.0], [3.0, 1.6])) 'continuous-multioutput' >>> type_of_target(np.array([0, 1], [1, 1])) 'multilabel-indicator'

val unique_labels : Py.Object.t list -> [> `ArrayLike ] Np.Obj.t

Extract an ordered array of unique labels

We don't allow:

  • mix of multilabel and multiclass (single label) targets
  • mix of label indicator matrix and anything else, because there are no explicit labels)
  • mix of label indicator matrices of different sizes
  • mix of string and integer labels

At the moment, we also don't allow 'multiclass-multioutput' input type.

Parameters ---------- *ys : array-likes

Returns ------- out : numpy array of shape n_unique_labels An ordered array of unique labels.

Examples -------- >>> from sklearn.utils.multiclass import unique_labels >>> unique_labels(3, 5, 5, 5, 7, 7) array(3, 5, 7) >>> unique_labels(1, 2, 3, 4, 2, 2, 3, 4) array(1, 2, 3, 4) >>> unique_labels(1, 2, 10, 5, 11) array( 1, 2, 5, 10, 11)

OCaml

Innovation. Community. Security.