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 CompoundKernel : sig ... end
module ConstantKernel : sig ... end
module DotProduct : sig ... end
module ExpSineSquared : sig ... end
module Exponentiation : sig ... end
module GenericKernelMixin : sig ... end
module Hyperparameter : sig ... end
module Kernel : sig ... end
module KernelOperator : sig ... end
module Matern : sig ... end
module NormalizedKernelMixin : sig ... end
module PairwiseKernel : sig ... end
module Product : sig ... end
module RBF : sig ... end
module RationalQuadratic : sig ... end
module StationaryKernelMixin : sig ... end
module Sum : sig ... end
module WhiteKernel : sig ... end
val abstractmethod : Py.Object.t -> Py.Object.t

A decorator indicating abstract methods.

Requires that the metaclass is ABCMeta or derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods are overridden. The abstract methods can be called using any of the normal 'super' call mechanisms. abstractmethod() may be used to declare abstract methods for properties and descriptors.

Usage:

class C(metaclass=ABCMeta): @abstractmethod def my_abstract_method(self, ...): ...

val cdist : ?metric:[ `S of string | `Callable of Py.Object.t ] -> ?kwargs:(string * Py.Object.t) list -> xa:[> `ArrayLike ] Np.Obj.t -> xb:[> `ArrayLike ] Np.Obj.t -> Py.Object.t list -> [> `ArrayLike ] Np.Obj.t

Compute distance between each pair of the two collections of inputs.

See Notes for common calling conventions.

Parameters ---------- XA : ndarray An :math:`m_A` by :math:`n` array of :math:`m_A` original observations in an :math:`n`-dimensional space. Inputs are converted to float type. XB : ndarray An :math:`m_B` by :math:`n` array of :math:`m_B` original observations in an :math:`n`-dimensional space. Inputs are converted to float type. metric : str or callable, optional The distance metric to use. If a string, the distance function can be 'braycurtis', 'canberra', 'chebyshev', 'cityblock', 'correlation', 'cosine', 'dice', 'euclidean', 'hamming', 'jaccard', 'jensenshannon', 'kulsinski', 'mahalanobis', 'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean', 'wminkowski', 'yule'. *args : tuple. Deprecated. Additional arguments should be passed as keyword arguments **kwargs : dict, optional Extra arguments to `metric`: refer to each metric documentation for a list of all possible arguments.

Some possible arguments:

p : scalar The p-norm to apply for Minkowski, weighted and unweighted. Default: 2.

w : ndarray The weight vector for metrics that support weights (e.g., Minkowski).

V : ndarray The variance vector for standardized Euclidean. Default: var(vstack(XA, XB), axis=0, ddof=1)

VI : ndarray The inverse of the covariance matrix for Mahalanobis. Default: inv(cov(vstack(XA, XB.T))).T

out : ndarray The output array If not None, the distance matrix Y is stored in this array. Note: metric independent, it will become a regular keyword arg in a future scipy version

Returns ------- Y : ndarray A :math:`m_A` by :math:`m_B` distance matrix is returned. For each :math:`i` and :math:`j`, the metric ``dist(u=XAi, v=XBj)`` is computed and stored in the :math:`ij` th entry.

Raises ------ ValueError An exception is thrown if `XA` and `XB` do not have the same number of columns.

Notes ----- The following are common calling conventions:

1. ``Y = cdist(XA, XB, 'euclidean')``

Computes the distance between :math:`m` points using Euclidean distance (2-norm) as the distance metric between the points. The points are arranged as :math:`m` :math:`n`-dimensional row vectors in the matrix X.

2. ``Y = cdist(XA, XB, 'minkowski', p=2.)``

Computes the distances using the Minkowski distance :math:`||u-v||_p` (:math:`p`-norm) where :math:`p \geq 1`.

3. ``Y = cdist(XA, XB, 'cityblock')``

Computes the city block or Manhattan distance between the points.

4. ``Y = cdist(XA, XB, 'seuclidean', V=None)``

Computes the standardized Euclidean distance. The standardized Euclidean distance between two n-vectors ``u`` and ``v`` is

.. math::

\sqrt\sum {(u_i-v_i)^2 / V[x_i]

}

.

V is the variance vector; Vi is the variance computed over all the i'th components of the points. If not passed, it is automatically computed.

5. ``Y = cdist(XA, XB, 'sqeuclidean')``

Computes the squared Euclidean distance :math:`||u-v||_2^2` between the vectors.

6. ``Y = cdist(XA, XB, 'cosine')``

Computes the cosine distance between vectors u and v,

.. math::

1 - \fracu \cdot v { ||u|| _2 ||v|| _2

}

where :math:`||*||_2` is the 2-norm of its argument ``*``, and :math:`u \cdot v` is the dot product of :math:`u` and :math:`v`.

7. ``Y = cdist(XA, XB, 'correlation')``

Computes the correlation distance between vectors u and v. This is

.. math::

1 - \frac(u - \bar{u) \cdot (v - \bar

})}
               {{ ||(u - \bar{u})|| }_2 { ||(v - \bar{v})|| }_2}

   where :math:`\bar{v}` is the mean of the elements of vector v,
   and :math:`x \cdot y` is the dot product of :math:`x` and :math:`y`.


8. ``Y = cdist(XA, XB, 'hamming')``

   Computes the normalized Hamming distance, or the proportion of
   those vector elements between two n-vectors ``u`` and ``v``
   which disagree. To save memory, the matrix ``X`` can be of type
   boolean.

9. ``Y = cdist(XA, XB, 'jaccard')``

   Computes the Jaccard distance between the points. Given two
   vectors, ``u`` and ``v``, the Jaccard distance is the
   proportion of those elements ``u[i]`` and ``v[i]`` that
   disagree where at least one of them is non-zero.

10. ``Y = cdist(XA, XB, 'chebyshev')``

   Computes the Chebyshev distance between the points. The
   Chebyshev distance between two n-vectors ``u`` and ``v`` is the
   maximum norm-1 distance between their respective elements. More
   precisely, the distance is given by

   .. math::

      d(u,v) = \max_i { |u_i-v_i| }.

11. ``Y = cdist(XA, XB, 'canberra')``

   Computes the Canberra distance between the points. The
   Canberra distance between two points ``u`` and ``v`` is

   .. math::

     d(u,v) = \sum_i \frac{ |u_i-v_i| }
                          { |u_i|+|v_i| }.

12. ``Y = cdist(XA, XB, 'braycurtis')``

   Computes the Bray-Curtis distance between the points. The
   Bray-Curtis distance between two points ``u`` and ``v`` is


   .. math::

        d(u,v) = \frac{\sum_i (|u_i-v_i|)}
                      {\sum_i (|u_i+v_i|)}

13. ``Y = cdist(XA, XB, 'mahalanobis', VI=None)``

   Computes the Mahalanobis distance between the points. The
   Mahalanobis distance between two points ``u`` and ``v`` is
   :math:`\sqrt{(u-v)(1/V)(u-v)^T}` where :math:`(1/V)` (the ``VI``
   variable) is the inverse covariance. If ``VI`` is not None,
   ``VI`` will be used as the inverse covariance matrix.

14. ``Y = cdist(XA, XB, 'yule')``

   Computes the Yule distance between the boolean
   vectors. (see `yule` function documentation)

15. ``Y = cdist(XA, XB, 'matching')``

   Synonym for 'hamming'.

16. ``Y = cdist(XA, XB, 'dice')``

   Computes the Dice distance between the boolean vectors. (see
   `dice` function documentation)

17. ``Y = cdist(XA, XB, 'kulsinski')``

   Computes the Kulsinski distance between the boolean
   vectors. (see `kulsinski` function documentation)

18. ``Y = cdist(XA, XB, 'rogerstanimoto')``

   Computes the Rogers-Tanimoto distance between the boolean
   vectors. (see `rogerstanimoto` function documentation)

19. ``Y = cdist(XA, XB, 'russellrao')``

   Computes the Russell-Rao distance between the boolean
   vectors. (see `russellrao` function documentation)

20. ``Y = cdist(XA, XB, 'sokalmichener')``

   Computes the Sokal-Michener distance between the boolean
   vectors. (see `sokalmichener` function documentation)

21. ``Y = cdist(XA, XB, 'sokalsneath')``

   Computes the Sokal-Sneath distance between the vectors. (see
   `sokalsneath` function documentation)


22. ``Y = cdist(XA, XB, 'wminkowski', p=2., w=w)``

   Computes the weighted Minkowski distance between the
   vectors. (see `wminkowski` function documentation)

23. ``Y = cdist(XA, XB, f)``

   Computes the distance between all pairs of vectors in X
   using the user supplied 2-arity function f. For example,
   Euclidean distance between the vectors could be computed
   as follows::

     dm = cdist(XA, XB, lambda u, v: np.sqrt(((u-v)**2).sum()))

   Note that you should avoid passing a reference to one of
   the distance functions defined in this library. For example,::

     dm = cdist(XA, XB, sokalsneath)

   would calculate the pair-wise distances between the vectors in
   X using the Python function `sokalsneath`. This would result in
   sokalsneath being called :math:`{n \choose 2}` times, which
   is inefficient. Instead, the optimized C version is more
   efficient, and we call it using the following syntax::

     dm = cdist(XA, XB, 'sokalsneath')

Examples
--------
Find the Euclidean distances between four 2-D coordinates:

>>> from scipy.spatial import distance
>>> coords = [(35.0456, -85.2672),
...           (35.1174, -89.9711),
...           (35.9728, -83.9422),
...           (36.1667, -86.7833)]
>>> distance.cdist(coords, coords, 'euclidean')
array([[ 0.    ,  4.7044,  1.6172,  1.8856],
       [ 4.7044,  0.    ,  6.0893,  3.3561],
       [ 1.6172,  6.0893,  0.    ,  2.8477],
       [ 1.8856,  3.3561,  2.8477,  0.    ]])


Find the Manhattan distance from a 3-D point to the corners of the unit
cube:

>>> a = np.array([[0, 0, 0],
...               [0, 0, 1],
...               [0, 1, 0],
...               [0, 1, 1],
...               [1, 0, 0],
...               [1, 0, 1],
...               [1, 1, 0],
...               [1, 1, 1]])
>>> b = np.array([[ 0.1,  0.2,  0.4]])
>>> distance.cdist(a, b, 'cityblock')
array([[ 0.7],
       [ 0.9],
       [ 1.3],
       [ 1.5],
       [ 1.5],
       [ 1.7],
       [ 2.1],
       [ 2.3]])
val clone : ?safe:bool -> estimator:[> `BaseEstimator ] Np.Obj.t -> unit -> Py.Object.t

Constructs a new estimator with the same parameters.

Clone does a deep copy of the model in an estimator without actually copying attached data. It yields a new estimator with the same parameters that has not been fit on any data.

Parameters ---------- estimator :

st, tuple, set

}

of estimator objects or estimator object The estimator or group of estimators to be cloned.

safe : bool, default=True If safe is false, clone will fall back to a deep copy on objects that are not estimators.

val gamma : ?out:Py.Object.t -> ?where:Py.Object.t -> x:Py.Object.t -> unit -> Py.Object.t

gamma(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True, signature, extobj)

gamma(z)

gamma function.

The gamma function is defined as

.. math::

\Gamma(z) = \int_0^\infty t^z-1 e^

t

}

dt

for :math:`\Re(z) > 0` and is extended to the rest of the complex plane by analytic continuation. See dlmf_ for more details.

Parameters ---------- z : array_like Real or complex valued argument

Returns ------- scalar or ndarray Values of the gamma function

Notes ----- The gamma function is often referred to as the generalized factorial since :math:`\Gamma(n + 1) = n!` for natural numbers :math:`n`. More generally it satisfies the recurrence relation :math:`\Gamma(z + 1) = z \cdot \Gamma(z)` for complex :math:`z`, which, combined with the fact that :math:`\Gamma(1) = 1`, implies the above identity for :math:`z = n`.

References ---------- .. dlmf NIST Digital Library of Mathematical Functions https://dlmf.nist.gov/5.2#E1

Examples -------- >>> from scipy.special import gamma, factorial

>>> gamma(0, 0.5, 1, 5) array( inf, 1.77245385, 1. , 24. )

>>> z = 2.5 + 1j >>> gamma(z) (0.77476210455108352+0.70763120437959293j) >>> gamma(z+1), z*gamma(z) # Recurrence property ((1.2292740569981171+2.5438401155000685j), (1.2292740569981158+2.5438401155000658j))

>>> gamma(0.5)**2 # gamma(0.5) = sqrt(pi) 3.1415926535897927

Plot gamma(x) for real x

>>> x = np.linspace(-3.5, 5.5, 2251) >>> y = gamma(x)

>>> import matplotlib.pyplot as plt >>> plt.plot(x, y, 'b', alpha=0.6, label='gamma(x)') >>> k = np.arange(1, 7) >>> plt.plot(k, factorial(k-1), 'k*', alpha=0.6, ... label='(x-1)!, x = 1, 2, ...') >>> plt.xlim(-3.5, 5.5) >>> plt.ylim(-10, 25) >>> plt.grid() >>> plt.xlabel('x') >>> plt.legend(loc='lower right') >>> plt.show()

val kv : ?out:Py.Object.t -> ?where:Py.Object.t -> x:Py.Object.t -> unit -> [> `ArrayLike ] Np.Obj.t

kv(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True, signature, extobj)

kv(v, z)

Modified Bessel function of the second kind of real order `v`

Returns the modified Bessel function of the second kind for real order `v` at complex `z`.

These are also sometimes called functions of the third kind, Basset functions, or Macdonald functions. They are defined as those solutions of the modified Bessel equation for which,

.. math:: K_v(x) \sim \sqrt\pi/(2x) \exp(-x)

as :math:`x \to \infty` 3_.

Parameters ---------- v : array_like of float Order of Bessel functions z : array_like of complex Argument at which to evaluate the Bessel functions

Returns ------- out : ndarray The results. Note that input must be of complex type to get complex output, e.g. ``kv(3, -2+0j)`` instead of ``kv(3, -2)``.

Notes ----- Wrapper for AMOS 1_ routine `zbesk`. For a discussion of the algorithm used, see 2_ and the references therein.

See Also -------- kve : This function with leading exponential behavior stripped off. kvp : Derivative of this function

References ---------- .. 1 Donald E. Amos, 'AMOS, A Portable Package for Bessel Functions of a Complex Argument and Nonnegative Order', http://netlib.org/amos/ .. 2 Donald E. Amos, 'Algorithm 644: A portable package for Bessel functions of a complex argument and nonnegative order', ACM TOMS Vol. 12 Issue 3, Sept. 1986, p. 265 .. 3 NIST Digital Library of Mathematical Functions, Eq. 10.25.E3. https://dlmf.nist.gov/10.25.E3

Examples -------- Plot the function of several orders for real input:

>>> from scipy.special import kv >>> import matplotlib.pyplot as plt >>> x = np.linspace(0, 5, 1000) >>> for N in np.linspace(0, 6, 5): ... plt.plot(x, kv(N, x), label='$K_{{

}

}

(x)$'.format(N)) >>> plt.ylim(0, 10) >>> plt.legend() >>> plt.title(r'Modified Bessel function of the second kind $K_\nu(x)$') >>> plt.show()

Calculate for a single value at multiple orders:

>>> kv(4, 4.5, 5, 1+2j) array( 0.1992+2.3892j, 2.3493+3.6j , 7.2827+3.8104j)

val namedtuple : ?rename:Py.Object.t -> ?defaults:Py.Object.t -> ?module_:Py.Object.t -> typename:Py.Object.t -> field_names:Py.Object.t -> unit -> Py.Object.t

Returns a new subclass of tuple with named fields.

>>> Point = namedtuple('Point', 'x', 'y') >>> Point.__doc__ # docstring for the new class 'Point(x, y)' >>> p = Point(11, y=22) # instantiate with positional args or keywords >>> p0 + p1 # indexable like a plain tuple 33 >>> x, y = p # unpack like a regular tuple >>> x, y (11, 22) >>> p.x + p.y # fields also accessible by name 33 >>> d = p._asdict() # convert to a dictionary >>> d'x' 11 >>> Point( **d) # convert from a dictionary Point(x=11, y=22) >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields Point(x=100, y=22)

val pairwise_kernels : ?y:[> `ArrayLike ] Np.Obj.t -> ?metric:[ `S of string | `Callable of Py.Object.t ] -> ?filter_params:bool -> ?n_jobs:int -> ?kwds:(string * Py.Object.t) list -> x:[ `Otherwise of Py.Object.t | `Arr of [> `ArrayLike ] Np.Obj.t ] -> unit -> [> `ArrayLike ] Np.Obj.t

Compute the kernel between arrays X and optional array Y.

This method takes either a vector array or a kernel matrix, and returns a kernel matrix. If the input is a vector array, the kernels are computed. If the input is a kernel matrix, it is returned instead.

This method provides a safe way to take a kernel matrix as input, while preserving compatibility with many other algorithms that take a vector array.

If Y is given (default is None), then the returned matrix is the pairwise kernel between the arrays from both X and Y.

Valid values for metric are: 'additive_chi2', 'chi2', 'linear', 'poly', 'polynomial', 'rbf', 'laplacian', 'sigmoid', 'cosine'

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

Parameters ---------- X : array n_samples_a, n_samples_a if metric == 'precomputed', or, n_samples_a, n_features otherwise Array of pairwise kernels between samples, or a feature array.

Y : array n_samples_b, n_features A second feature array only if X has shape n_samples_a, n_features.

metric : string, or callable The metric to use when calculating kernel between instances in a feature array. If metric is a string, it must be one of the metrics in pairwise.PAIRWISE_KERNEL_FUNCTIONS. If metric is 'precomputed', X is assumed to be a kernel matrix. Alternatively, if metric is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two rows from X as input and return the corresponding kernel value as a single number. This means that callables from :mod:`sklearn.metrics.pairwise` are not allowed, as they operate on matrices, not single samples. Use the string identifying the kernel instead.

filter_params : boolean Whether to filter invalid parameters or not.

n_jobs : int or None, optional (default=None) The number of jobs to use for the computation. This works by breaking down the pairwise matrix into n_jobs even slices and computing them in parallel.

``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. ``-1`` means using all processors. See :term:`Glossary <n_jobs>` for more details.

**kwds : optional keyword parameters Any further parameters are passed directly to the kernel function.

Returns ------- K : array n_samples_a, n_samples_a or n_samples_a, n_samples_b A kernel matrix K such that K_, j is the kernel between the ith and jth vectors of the given matrix X, if Y is None. If Y is not None, then K_, j is the kernel between the ith array from X and the jth array from Y.

Notes ----- If metric is 'precomputed', Y is ignored and X is returned.

val pdist : ?metric:[ `S of string | `Callable of Py.Object.t ] -> ?kwargs:(string * Py.Object.t) list -> x:[> `ArrayLike ] Np.Obj.t -> Py.Object.t list -> [> `ArrayLike ] Np.Obj.t

Pairwise distances between observations in n-dimensional space.

See Notes for common calling conventions.

Parameters ---------- X : ndarray An m by n array of m original observations in an n-dimensional space. metric : str or function, optional The distance metric to use. The distance function can be 'braycurtis', 'canberra', 'chebyshev', 'cityblock', 'correlation', 'cosine', 'dice', 'euclidean', 'hamming', 'jaccard', 'jensenshannon', 'kulsinski', 'mahalanobis', 'matching', 'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean', 'yule'. *args : tuple. Deprecated. Additional arguments should be passed as keyword arguments **kwargs : dict, optional Extra arguments to `metric`: refer to each metric documentation for a list of all possible arguments.

Some possible arguments:

p : scalar The p-norm to apply for Minkowski, weighted and unweighted. Default: 2.

w : ndarray The weight vector for metrics that support weights (e.g., Minkowski).

V : ndarray The variance vector for standardized Euclidean. Default: var(X, axis=0, ddof=1)

VI : ndarray The inverse of the covariance matrix for Mahalanobis. Default: inv(cov(X.T)).T

out : ndarray. The output array If not None, condensed distance matrix Y is stored in this array. Note: metric independent, it will become a regular keyword arg in a future scipy version

Returns ------- Y : ndarray Returns a condensed distance matrix Y. For each :math:`i` and :math:`j` (where :math:`i<j<m`),where m is the number of original observations. The metric ``dist(u=Xi, v=Xj)`` is computed and stored in entry ``ij``.

See Also -------- squareform : converts between condensed distance matrices and square distance matrices.

Notes ----- See ``squareform`` for information on how to calculate the index of this entry or to convert the condensed distance matrix to a redundant square matrix.

The following are common calling conventions.

1. ``Y = pdist(X, 'euclidean')``

Computes the distance between m points using Euclidean distance (2-norm) as the distance metric between the points. The points are arranged as m n-dimensional row vectors in the matrix X.

2. ``Y = pdist(X, 'minkowski', p=2.)``

Computes the distances using the Minkowski distance :math:`||u-v||_p` (p-norm) where :math:`p \geq 1`.

3. ``Y = pdist(X, 'cityblock')``

Computes the city block or Manhattan distance between the points.

4. ``Y = pdist(X, 'seuclidean', V=None)``

Computes the standardized Euclidean distance. The standardized Euclidean distance between two n-vectors ``u`` and ``v`` is

.. math::

\sqrt\sum {(u_i-v_i)^2 / V[x_i]

}

V is the variance vector; Vi is the variance computed over all the i'th components of the points. If not passed, it is automatically computed.

5. ``Y = pdist(X, 'sqeuclidean')``

Computes the squared Euclidean distance :math:`||u-v||_2^2` between the vectors.

6. ``Y = pdist(X, 'cosine')``

Computes the cosine distance between vectors u and v,

.. math::

1 - \fracu \cdot v { ||u|| _2 ||v|| _2

}

where :math:`||*||_2` is the 2-norm of its argument ``*``, and :math:`u \cdot v` is the dot product of ``u`` and ``v``.

7. ``Y = pdist(X, 'correlation')``

Computes the correlation distance between vectors u and v. This is

.. math::

1 - \frac(u - \bar{u) \cdot (v - \bar

})}
               {{ ||(u - \bar{u})|| }_2 { ||(v - \bar{v})|| }_2}

   where :math:`\bar{v}` is the mean of the elements of vector v,
   and :math:`x \cdot y` is the dot product of :math:`x` and :math:`y`.

8. ``Y = pdist(X, 'hamming')``

   Computes the normalized Hamming distance, or the proportion of
   those vector elements between two n-vectors ``u`` and ``v``
   which disagree. To save memory, the matrix ``X`` can be of type
   boolean.

9. ``Y = pdist(X, 'jaccard')``

   Computes the Jaccard distance between the points. Given two
   vectors, ``u`` and ``v``, the Jaccard distance is the
   proportion of those elements ``u[i]`` and ``v[i]`` that
   disagree.

10. ``Y = pdist(X, 'chebyshev')``

   Computes the Chebyshev distance between the points. The
   Chebyshev distance between two n-vectors ``u`` and ``v`` is the
   maximum norm-1 distance between their respective elements. More
   precisely, the distance is given by

   .. math::

      d(u,v) = \max_i { |u_i-v_i| }

11. ``Y = pdist(X, 'canberra')``

   Computes the Canberra distance between the points. The
   Canberra distance between two points ``u`` and ``v`` is

   .. math::

     d(u,v) = \sum_i \frac{ |u_i-v_i| }
                          { |u_i|+|v_i| }


12. ``Y = pdist(X, 'braycurtis')``

   Computes the Bray-Curtis distance between the points. The
   Bray-Curtis distance between two points ``u`` and ``v`` is


   .. math::

        d(u,v) = \frac{\sum_i { |u_i-v_i| }}
                       {\sum_i { |u_i+v_i| }}

13. ``Y = pdist(X, 'mahalanobis', VI=None)``

   Computes the Mahalanobis distance between the points. The
   Mahalanobis distance between two points ``u`` and ``v`` is
   :math:`\sqrt{(u-v)(1/V)(u-v)^T}` where :math:`(1/V)` (the ``VI``
   variable) is the inverse covariance. If ``VI`` is not None,
   ``VI`` will be used as the inverse covariance matrix.

14. ``Y = pdist(X, 'yule')``

   Computes the Yule distance between each pair of boolean
   vectors. (see yule function documentation)

15. ``Y = pdist(X, 'matching')``

   Synonym for 'hamming'.

16. ``Y = pdist(X, 'dice')``

   Computes the Dice distance between each pair of boolean
   vectors. (see dice function documentation)

17. ``Y = pdist(X, 'kulsinski')``

   Computes the Kulsinski distance between each pair of
   boolean vectors. (see kulsinski function documentation)

18. ``Y = pdist(X, 'rogerstanimoto')``

   Computes the Rogers-Tanimoto distance between each pair of
   boolean vectors. (see rogerstanimoto function documentation)

19. ``Y = pdist(X, 'russellrao')``

   Computes the Russell-Rao distance between each pair of
   boolean vectors. (see russellrao function documentation)

20. ``Y = pdist(X, 'sokalmichener')``

   Computes the Sokal-Michener distance between each pair of
   boolean vectors. (see sokalmichener function documentation)

21. ``Y = pdist(X, 'sokalsneath')``

   Computes the Sokal-Sneath distance between each pair of
   boolean vectors. (see sokalsneath function documentation)

22. ``Y = pdist(X, 'wminkowski', p=2, w=w)``

   Computes the weighted Minkowski distance between each pair of
   vectors. (see wminkowski function documentation)

23. ``Y = pdist(X, f)``

   Computes the distance between all pairs of vectors in X
   using the user supplied 2-arity function f. For example,
   Euclidean distance between the vectors could be computed
   as follows::

     dm = pdist(X, lambda u, v: np.sqrt(((u-v)**2).sum()))

   Note that you should avoid passing a reference to one of
   the distance functions defined in this library. For example,::

     dm = pdist(X, sokalsneath)

   would calculate the pair-wise distances between the vectors in
   X using the Python function sokalsneath. This would result in
   sokalsneath being called :math:`{n \choose 2}` times, which
   is inefficient. Instead, the optimized C version is more
   efficient, and we call it using the following syntax.::

     dm = pdist(X, 'sokalsneath')
val signature : ?follow_wrapped:Py.Object.t -> obj:Py.Object.t -> unit -> Py.Object.t

Get a signature object for the passed callable.

val squareform : ?force:string -> ?checks:bool -> x:[> `ArrayLike ] Np.Obj.t -> unit -> [> `ArrayLike ] Np.Obj.t

Convert a vector-form distance vector to a square-form distance matrix, and vice-versa.

Parameters ---------- X : ndarray Either a condensed or redundant distance matrix. force : str, optional As with MATLAB(TM), if force is equal to ``'tovector'`` or ``'tomatrix'``, the input will be treated as a distance matrix or distance vector respectively. checks : bool, optional If set to False, no checks will be made for matrix symmetry nor zero diagonals. This is useful if it is known that ``X - X.T1`` is small and ``diag(X)`` is close to zero. These values are ignored any way so they do not disrupt the squareform transformation.

Returns ------- Y : ndarray If a condensed distance matrix is passed, a redundant one is returned, or if a redundant one is passed, a condensed distance matrix is returned.

Notes ----- 1. ``v = squareform(X)``

Given a square n-by-n symmetric distance matrix ``X``, ``v = squareform(X)`` returns a ``n * (n-1) / 2`` (i.e. binomial coefficient n choose 2) sized vector `v` where :math:`v{n \choose 2} - {n-i \choose 2} + (j-i-1)` is the distance between distinct points ``i`` and ``j``. If ``X`` is non-square or asymmetric, an error is raised.

2. ``X = squareform(v)``

Given a ``n * (n-1) / 2`` sized vector ``v`` for some integer ``n >= 1`` encoding distances as described, ``X = squareform(v)`` returns a n-by-n distance matrix ``X``. The ``Xi, j`` and ``Xj, i`` values are set to :math:`v{n \choose 2} - {n-i \choose 2} + (j-i-1)` and all diagonal elements are zero.

In SciPy 0.19.0, ``squareform`` stopped casting all input types to float64, and started returning arrays of the same dtype as the input.

OCaml

Innovation. Community. Security.