neulab/docprompting-conala huggingface dataset:
sklearn.metrics.pairwise.euclidean_distances  
sklearn.metrics.pairwise.euclidean_distances(X, Y=None, *, Y_norm_squared=None, squared=False, X_norm_squared=None) [source]
 
Considering the rows of X (and Y=X) as vectors, compute the distance matrix between each pair of vectors. For efficiency reasons, the euclidean distance between a pair of row vector x and y is computed as: dist(x, y) = sqrt(dot(x, x) - 2 * dot(x, y) + dot(y, y))
 This formulation has two advantages over other ways of computing distances. First, it is computationally efficient when dealing with sparse data. Second, if one argument varies but the other remains unchanged, then dot(x, x) and/or dot(y, y) can be pre-computed. However, this is not the most precise way of doing this computation, because this equation potentially suffers from “catastrophic cancellation”. Also, the distance matrix returned by this function may not be exactly symmetric as required by, e.g., scipy.spatial.distance functions. Read more in the User Guide.  Parameters 
 
X{array-like, sparse matrix} of shape (n_samples_X, n_features) 

Y{array-like, sparse matrix} of shape (n_samples_Y, n_features), default=None 

Y_norm_squaredarray-like of shape (n_samples_Y,), default=None 

Pre-computed dot-products of vectors in Y (e.g., (Y**2).sum(axis=1)) May be ignored in some cases, see the note below.  
squaredbool, default=False 

Return squared Euclidean distances.  
X_norm_squaredarray-like of shape (n_samples,), default=None 

Pre-computed dot-products of vectors in X (e.g., (X**2).sum(axis=1)) May be ignored in some cases, see the note below.    Returns 
 
distancesndarray of shape (n_samples_X, n_samples_Y) 
    See also  
paired_distances


Distances betweens pairs of elements of X and Y.    Notes To achieve better accuracy, X_norm_squared and Y_norm_squared may be unused if they are passed as float32. Examples >>> from sklearn.metrics.pairwise import euclidean_distances
>>> X = [[0, 1], [1, 1]]
>>> # distance between rows of X
>>> euclidean_distances(X, X)
array([[0., 1.],
       [1., 0.]])
>>> # get distance to origin
>>> euclidean_distances(X, [[0, 0]])
array([[1.        ],
       [1.41421356]])
sklearn.metrics.pairwise.haversine_distances  
sklearn.metrics.pairwise.haversine_distances(X, Y=None) [source]
 
Compute the Haversine distance between samples in X and Y. The Haversine (or great circle) distance is the angular distance between two points on the surface of a sphere. The first coordinate of each point is assumed to be the latitude, the second is the longitude, given in radians. The dimension of the data must be 2.  \[D(x, y) = 2\arcsin[\sqrt{\sin^2((x1 - y1) / 2) + \cos(x1)\cos(y1)\sin^2((x2 - y2) / 2)}]\]  Parameters 
 
Xarray-like of shape (n_samples_X, 2) 

Yarray-like of shape (n_samples_Y, 2), default=None 
  Returns 
 
distancendarray of shape (n_samples_X, n_samples_Y) 
   Notes As the Earth is nearly spherical, the haversine formula provides a good approximation of the distance between two points of the Earth surface, with a less than 1% error on average. Examples We want to calculate the distance between the Ezeiza Airport (Buenos Aires, Argentina) and the Charles de Gaulle Airport (Paris, France). >>> from sklearn.metrics.pairwise import haversine_distances
>>> from math import radians
>>> bsas = [-34.83333, -58.5166646]
>>> paris = [49.0083899664, 2.53844117956]
>>> bsas_in_radians = [radians(_) for _ in bsas]
>>> paris_in_radians = [radians(_) for _ in paris]
>>> result = haversine_distances([bsas_in_radians, paris_in_radians])
>>> result * 6371000/1000  # multiply by Earth radius to get kilometers
array([[    0.        , 11099.54035582],
       [11099.54035582,     0.        ]])
sklearn.metrics.pairwise.kernel_metrics  
sklearn.metrics.pairwise.kernel_metrics() [source]
 
Valid metrics for pairwise_kernels. This function simply returns the valid pairwise distance metrics. It exists, however, to allow for a verbose description of the mapping for each of the valid strings.  The valid distance metrics, and the function they map to, are:

  
metric Function   
‘additive_chi2’ sklearn.pairwise.additive_chi2_kernel  
‘chi2’ sklearn.pairwise.chi2_kernel  
‘linear’ sklearn.pairwise.linear_kernel  
‘poly’ sklearn.pairwise.polynomial_kernel  
‘polynomial’ sklearn.pairwise.polynomial_kernel  
‘rbf’ sklearn.pairwise.rbf_kernel  
‘laplacian’ sklearn.pairwise.laplacian_kernel  
‘sigmoid’ sklearn.pairwise.sigmoid_kernel  
‘cosine’ sklearn.pairwise.cosine_similarity     Read more in the User Guide.
sklearn.metrics.pairwise.laplacian_kernel  
sklearn.metrics.pairwise.laplacian_kernel(X, Y=None, gamma=None) [source]
 
Compute the laplacian kernel between X and Y. The laplacian kernel is defined as: K(x, y) = exp(-gamma ||x-y||_1)
 for each pair of rows x in X and y in Y. Read more in the User Guide.  New in version 0.17.   Parameters 
 
Xndarray of shape (n_samples_X, n_features) 

Yndarray of shape (n_samples_Y, n_features), default=None 

gammafloat, default=None 

If None, defaults to 1.0 / n_features.    Returns 
 
kernel_matrixndarray of shape (n_samples_X, n_samples_Y)
sklearn.metrics.pairwise.linear_kernel  
sklearn.metrics.pairwise.linear_kernel(X, Y=None, dense_output=True) [source]
 
Compute the linear kernel between X and Y. Read more in the User Guide.  Parameters 
 
Xndarray of shape (n_samples_X, n_features) 

Yndarray of shape (n_samples_Y, n_features), default=None 

dense_outputbool, default=True 

Whether to return dense output even when the input is sparse. If False, the output is sparse if both input arrays are sparse.  New in version 0.20.     Returns 
 
Gram matrixndarray of shape (n_samples_X, n_samples_Y)
sklearn.metrics.pairwise.manhattan_distances  
sklearn.metrics.pairwise.manhattan_distances(X, Y=None, *, sum_over_features=True) [source]
 
Compute the L1 distances between the vectors in X and Y. With sum_over_features equal to False it returns the componentwise distances. Read more in the User Guide.  Parameters 
 
Xarray-like of shape (n_samples_X, n_features) 

Yarray-like of shape (n_samples_Y, n_features), default=None 

sum_over_featuresbool, default=True 

If True the function returns the pairwise distance matrix else it returns the componentwise L1 pairwise-distances. Not supported for sparse matrix inputs.    Returns 
 
Dndarray of shape (n_samples_X * n_samples_Y, n_features) or (n_samples_X, n_samples_Y) 

If sum_over_features is False shape is (n_samples_X * n_samples_Y, n_features) and D contains the componentwise L1 pairwise-distances (ie. absolute difference), else shape is (n_samples_X, n_samples_Y) and D contains the pairwise L1 distances.     Notes When X and/or Y are CSR sparse matrices and they are not already in canonical format, this function modifies them in-place to make them canonical. Examples >>> from sklearn.metrics.pairwise import manhattan_distances
>>> manhattan_distances([[3]], [[3]])
array([[0.]])
>>> manhattan_distances([[3]], [[2]])
array([[1.]])
>>> manhattan_distances([[2]], [[3]])
array([[1.]])
>>> manhattan_distances([[1, 2], [3, 4]],         [[1, 2], [0, 3]])
array([[0., 2.],
       [4., 4.]])
>>> import numpy as np
>>> X = np.ones((1, 2))
>>> y = np.full((2, 2), 2.)
>>> manhattan_distances(X, y, sum_over_features=False)
array([[1., 1.],
       [1., 1.]])
sklearn.metrics.pairwise.nan_euclidean_distances  
sklearn.metrics.pairwise.nan_euclidean_distances(X, Y=None, *, squared=False, missing_values=nan, copy=True) [source]
 
Calculate the euclidean distances in the presence of missing values. Compute the euclidean distance between each pair of samples in X and Y, where Y=X is assumed if Y=None. When calculating the distance between a pair of samples, this formulation ignores feature coordinates with a missing value in either sample and scales up the weight of the remaining coordinates: dist(x,y) = sqrt(weight * sq. distance from present coordinates) where, weight = Total # of coordinates / # of present coordinates For example, the distance between [3, na, na, 6] and [1, na, 4, 5] is:  \[\sqrt{\frac{4}{2}((3-1)^2 + (6-5)^2)}\] If all the coordinates are missing or if there are no common present coordinates then NaN is returned for that pair. Read more in the User Guide.  New in version 0.22.   Parameters 
 
Xarray-like of shape=(n_samples_X, n_features) 

Yarray-like of shape=(n_samples_Y, n_features), default=None 

squaredbool, default=False 

Return squared Euclidean distances.  
missing_valuesnp.nan or int, default=np.nan 

Representation of missing value.  
copybool, default=True 

Make and use a deep copy of X and Y (if Y exists).    Returns 
 
distancesndarray of shape (n_samples_X, n_samples_Y) 
    See also  
paired_distances


Distances between pairs of elements of X and Y.    References  John K. Dixon, “Pattern Recognition with Partly Missing Data”, IEEE Transactions on Systems, Man, and Cybernetics, Volume: 9, Issue: 10, pp. 617 - 621, Oct. 1979. http://ieeexplore.ieee.org/abstract/document/4310090/
  Examples >>> from sklearn.metrics.pairwise import nan_euclidean_distances
>>> nan = float("NaN")
>>> X = [[0, 1], [1, nan]]
>>> nan_euclidean_distances(X, X) # distance between rows of X
array([[0.        , 1.41421356],
       [1.41421356, 0.        ]])
 >>> # get distance to origin
>>> nan_euclidean_distances(X, [[0, 0]])
array([[1.        ],
       [1.41421356]])
sklearn.metrics.pairwise.paired_cosine_distances  
sklearn.metrics.pairwise.paired_cosine_distances(X, Y) [source]
 
Computes the paired cosine distances between X and Y. Read more in the User Guide.  Parameters 
 
Xarray-like of shape (n_samples, n_features) 

Yarray-like of shape (n_samples, n_features) 
  Returns 
 
distancesndarray of shape (n_samples,) 
   Notes The cosine distance is equivalent to the half the squared euclidean distance if each sample is normalized to unit norm.
sklearn.metrics.pairwise.paired_distances  
sklearn.metrics.pairwise.paired_distances(X, Y, *, metric='euclidean', **kwds) [source]
 
Computes the paired distances between X and Y. Computes the distances between (X[0], Y[0]), (X[1], Y[1]), etc… Read more in the User Guide.  Parameters 
 
Xndarray of shape (n_samples, n_features) 

Array 1 for distance computation.  
Yndarray of shape (n_samples, n_features) 

Array 2 for distance computation.  
metricstr or callable, default=”euclidean” 

The metric to use when calculating distance between instances in a feature array. If metric is a string, it must be one of the options specified in PAIRED_DISTANCES, including “euclidean”, “manhattan”, or “cosine”. 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 arrays from X as input and return a value indicating the distance between them.    Returns 
 
distancesndarray of shape (n_samples,) 
    See also  
pairwise_distances 

Computes the distance between every pair of samples.    Examples >>> from sklearn.metrics.pairwise import paired_distances
>>> X = [[0, 1], [1, 1]]
>>> Y = [[0, 1], [2, 1]]
>>> paired_distances(X, Y)
array([0., 1.])
sklearn.metrics.pairwise.paired_euclidean_distances  
sklearn.metrics.pairwise.paired_euclidean_distances(X, Y) [source]
 
Computes the paired euclidean distances between X and Y. Read more in the User Guide.  Parameters 
 
Xarray-like of shape (n_samples, n_features) 

Yarray-like of shape (n_samples, n_features) 
  Returns 
 
distancesndarray of shape (n_samples,)
sklearn.metrics.pairwise.paired_manhattan_distances  
sklearn.metrics.pairwise.paired_manhattan_distances(X, Y) [source]
 
Compute the L1 distances between the vectors in X and Y. Read more in the User Guide.  Parameters 
 
Xarray-like of shape (n_samples, n_features) 

Yarray-like of shape (n_samples, n_features) 
  Returns 
 
distancesndarray of shape (n_samples,)
sklearn.metrics.pairwise.pairwise_kernels  
sklearn.metrics.pairwise.pairwise_kernels(X, Y=None, metric='linear', *, filter_params=False, n_jobs=None, **kwds) [source]
 
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 User Guide.  Parameters 
 
Xndarray of shape (n_samples_X, n_samples_X) or (n_samples_X, n_features) 

Array of pairwise kernels between samples, or a feature array. The shape of the array should be (n_samples_X, n_samples_X) if metric == “precomputed” and (n_samples_X, n_features) otherwise.  
Yndarray of shape (n_samples_Y, n_features), default=None 

A second feature array only if X has shape (n_samples_X, n_features).  
metricstr or callable, default=”linear” 

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 sklearn.metrics.pairwise are not allowed, as they operate on matrices, not single samples. Use the string identifying the kernel instead.  
filter_paramsbool, default=False 

Whether to filter invalid parameters or not.  
n_jobsint, 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 joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.  
**kwdsoptional keyword parameters 

Any further parameters are passed directly to the kernel function.    Returns 
 
Kndarray of shape (n_samples_X, n_samples_X) or (n_samples_X, n_samples_Y) 

A kernel matrix K such that K_{i, 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_{i, 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.
sklearn.metrics.pairwise.polynomial_kernel  
sklearn.metrics.pairwise.polynomial_kernel(X, Y=None, degree=3, gamma=None, coef0=1) [source]
 
Compute the polynomial kernel between X and Y: K(X, Y) = (gamma <X, Y> + coef0)^degree
 Read more in the User Guide.  Parameters 
 
Xndarray of shape (n_samples_X, n_features) 

Yndarray of shape (n_samples_Y, n_features), default=None 

degreeint, default=3 

gammafloat, default=None 

If None, defaults to 1.0 / n_features.  
coef0float, default=1 
  Returns 
 
Gram matrixndarray of shape (n_samples_X, n_samples_Y)
sklearn.metrics.pairwise.rbf_kernel  
sklearn.metrics.pairwise.rbf_kernel(X, Y=None, gamma=None) [source]
 
Compute the rbf (gaussian) kernel between X and Y: K(x, y) = exp(-gamma ||x-y||^2)
 for each pair of rows x in X and y in Y. Read more in the User Guide.  Parameters 
 
Xndarray of shape (n_samples_X, n_features) 

Yndarray of shape (n_samples_Y, n_features), default=None 

gammafloat, default=None 

If None, defaults to 1.0 / n_features.    Returns 
 
kernel_matrixndarray of shape (n_samples_X, n_samples_Y)
sklearn.metrics.pairwise.sigmoid_kernel  
sklearn.metrics.pairwise.sigmoid_kernel(X, Y=None, gamma=None, coef0=1) [source]
 
Compute the sigmoid kernel between X and Y: K(X, Y) = tanh(gamma <X, Y> + coef0)
 Read more in the User Guide.  Parameters 
 
Xndarray of shape (n_samples_X, n_features) 

Yndarray of shape (n_samples_Y, n_features), default=None 

gammafloat, default=None 

If None, defaults to 1.0 / n_features.  
coef0float, default=1 
  Returns 
 
Gram matrixndarray of shape (n_samples_X, n_samples_Y)
sklearn.metrics.pairwise_distances_argmin  
sklearn.metrics.pairwise_distances_argmin(X, Y, *, axis=1, metric='euclidean', metric_kwargs=None) [source]
 
Compute minimum distances between one point and a set of points. This function computes for each row in X, the index of the row of Y which is closest (according to the specified distance). This is mostly equivalent to calling: pairwise_distances(X, Y=Y, metric=metric).argmin(axis=axis) but uses much less memory, and is faster for large arrays. This function works with dense 2D arrays only.  Parameters 
 
Xarray-like of shape (n_samples_X, n_features) 

Array containing points.  
Yarray-like of shape (n_samples_Y, n_features) 

Arrays containing points.  
axisint, default=1 

Axis along which the argmin and distances are to be computed.  
metricstr or callable, default=”euclidean” 

Metric to use for distance computation. Any metric from scikit-learn or scipy.spatial.distance can be used. 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 arrays as input and return one value indicating the distance between them. This works for Scipy’s metrics, but is less efficient than passing the metric name as a string. Distance matrices are not supported. Valid values for metric are:  from scikit-learn: [‘cityblock’, ‘cosine’, ‘euclidean’, ‘l1’, ‘l2’, ‘manhattan’] from scipy.spatial.distance: [‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘correlation’, ‘dice’, ‘hamming’, ‘jaccard’, ‘kulsinski’, ‘mahalanobis’, ‘minkowski’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’]  See the documentation for scipy.spatial.distance for details on these metrics.  
metric_kwargsdict, default=None 

Keyword arguments to pass to specified metric function.    Returns 
 
argminnumpy.ndarray 

Y[argmin[i], :] is the row in Y that is closest to X[i, :].      See also  
sklearn.metrics.pairwise_distances


sklearn.metrics.pairwise_distances_argmin_min

  
 Examples using sklearn.metrics.pairwise_distances_argmin
 
  Color Quantization using K-Means  

  Comparison of the K-Means and MiniBatchKMeans clustering algorithms
sklearn.metrics.pairwise_distances_argmin_min  
sklearn.metrics.pairwise_distances_argmin_min(X, Y, *, axis=1, metric='euclidean', metric_kwargs=None) [source]
 
Compute minimum distances between one point and a set of points. This function computes for each row in X, the index of the row of Y which is closest (according to the specified distance). The minimal distances are also returned. This is mostly equivalent to calling:  (pairwise_distances(X, Y=Y, metric=metric).argmin(axis=axis),

pairwise_distances(X, Y=Y, metric=metric).min(axis=axis))   but uses much less memory, and is faster for large arrays.  Parameters 
 
X{array-like, sparse matrix} of shape (n_samples_X, n_features) 

Array containing points.  
Y{array-like, sparse matrix} of shape (n_samples_Y, n_features) 

Array containing points.  
axisint, default=1 

Axis along which the argmin and distances are to be computed.  
metricstr or callable, default=’euclidean’ 

Metric to use for distance computation. Any metric from scikit-learn or scipy.spatial.distance can be used. 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 arrays as input and return one value indicating the distance between them. This works for Scipy’s metrics, but is less efficient than passing the metric name as a string. Distance matrices are not supported. Valid values for metric are:  from scikit-learn: [‘cityblock’, ‘cosine’, ‘euclidean’, ‘l1’, ‘l2’, ‘manhattan’] from scipy.spatial.distance: [‘braycurtis’, ‘canberra’, ‘chebyshev’, ‘correlation’, ‘dice’, ‘hamming’, ‘jaccard’, ‘kulsinski’, ‘mahalanobis’, ‘minkowski’, ‘rogerstanimoto’, ‘russellrao’, ‘seuclidean’, ‘sokalmichener’, ‘sokalsneath’, ‘sqeuclidean’, ‘yule’]  See the documentation for scipy.spatial.distance for details on these metrics.  
metric_kwargsdict, default=None 

Keyword arguments to pass to specified metric function.    Returns 
 
argminndarray 

Y[argmin[i], :] is the row in Y that is closest to X[i, :].  
distancesndarray 

distances[i] is the distance between the i-th row in X and the argmin[i]-th row in Y.      See also  
sklearn.metrics.pairwise_distances


sklearn.metrics.pairwise_distances_argmin
sklearn.metrics.plot_confusion_matrix  
sklearn.metrics.plot_confusion_matrix(estimator, X, y_true, *, labels=None, sample_weight=None, normalize=None, display_labels=None, include_values=True, xticks_rotation='horizontal', values_format=None, cmap='viridis', ax=None, colorbar=True) [source]
 
Plot Confusion Matrix. Read more in the User Guide.  Parameters 
 
estimatorestimator instance 

Fitted classifier or a fitted Pipeline in which the last estimator is a classifier.  
X{array-like, sparse matrix} of shape (n_samples, n_features) 

Input values.  
y_truearray-like of shape (n_samples,) 

Target values.  
labelsarray-like of shape (n_classes,), default=None 

List of labels to index the matrix. This may be used to reorder or select a subset of labels. If None is given, those that appear at least once in y_true or y_pred are used in sorted order.  
sample_weightarray-like of shape (n_samples,), default=None 

Sample weights.  
normalize{‘true’, ‘pred’, ‘all’}, default=None 

Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, confusion matrix will not be normalized.  
display_labelsarray-like of shape (n_classes,), default=None 

Target names used for plotting. By default, labels will be used if it is defined, otherwise the unique labels of y_true and y_pred will be used.  
include_valuesbool, default=True 

Includes values in confusion matrix.  
xticks_rotation{‘vertical’, ‘horizontal’} or float, default=’horizontal’ 

Rotation of xtick labels.  
values_formatstr, default=None 

Format specification for values in confusion matrix. If None, the format specification is ‘d’ or ‘.2g’ whichever is shorter.  
cmapstr or matplotlib Colormap, default=’viridis’ 

Colormap recognized by matplotlib.  
axmatplotlib Axes, default=None 

Axes object to plot on. If None, a new figure and axes is created.  
colorbarbool, default=True 

Whether or not to add a colorbar to the plot.  New in version 0.24.     Returns 
 
displayConfusionMatrixDisplay 
    See also  
confusion_matrix


Compute Confusion Matrix to evaluate the accuracy of a classification.  
ConfusionMatrixDisplay


Confusion Matrix visualization.    Examples >>> import matplotlib.pyplot as plt  
>>> from sklearn.datasets import make_classification
>>> from sklearn.metrics import plot_confusion_matrix
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.svm import SVC
>>> X, y = make_classification(random_state=0)
>>> X_train, X_test, y_train, y_test = train_test_split(
...         X, y, random_state=0)
>>> clf = SVC(random_state=0)
>>> clf.fit(X_train, y_train)
SVC(random_state=0)
>>> plot_confusion_matrix(clf, X_test, y_test)  
>>> plt.show()  
 
 Examples using sklearn.metrics.plot_confusion_matrix
 
  Recognizing hand-written digits  

  Confusion matrix