neulab/docprompting-conala huggingface dataset:
sklearn.utils.estimator_checks.check_estimator  
sklearn.utils.estimator_checks.check_estimator(Estimator, generate_only=False) [source]
 
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.  Parameters 
 
Estimatorestimator object 

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.   
generate_onlybool, default=False 

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.     Returns 
 
checks_generatorgenerator 

Generator that yields (estimator, check) tuples. Returned when generate_only=True.
sklearn.utils.estimator_checks.parametrize_with_checks  
sklearn.utils.estimator_checks.parametrize_with_checks(estimators) [source]
 
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: pytest test_check_estimators.py -k check_estimators_fit_returns_self
  Parameters 
 
estimatorslist of estimators instances 

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.     Returns 
 
decoratorpytest.mark.parametrize 
   Examples >>> from sklearn.utils.estimator_checks import parametrize_with_checks
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.tree import DecisionTreeRegressor
 >>> @parametrize_with_checks([LogisticRegression(),
...                           DecisionTreeRegressor()])
... def test_sklearn_compatible_estimator(estimator, check):
...     check(estimator)
 
 Examples using sklearn.utils.estimator_checks.parametrize_with_checks
 
  Release Highlights for scikit-learn 0.22
sklearn.utils.estimator_html_repr  
sklearn.utils.estimator_html_repr(estimator) [source]
 
Build a HTML representation of an estimator. Read more in the User Guide.  Parameters 
 
estimatorestimator object 

The estimator to visualize.    Returns 
 html: str

HTML representation of estimator.
sklearn.utils.extmath.density  
sklearn.utils.extmath.density(w, **kwargs) [source]
 
Compute density of a sparse vector.  Parameters 
 
warray-like 

The sparse vector.    Returns 
 float

The density of w, between 0 and 1.     
 Examples using sklearn.utils.extmath.density
 
  Classification of text documents using sparse features
sklearn.utils.extmath.fast_logdet  
sklearn.utils.extmath.fast_logdet(A) [source]
 
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.  Parameters 
 
Aarray-like 

The matrix.
sklearn.utils.extmath.randomized_range_finder  
sklearn.utils.extmath.randomized_range_finder(A, *, size, n_iter, power_iteration_normalizer='auto', random_state=None) [source]
 
Computes an orthonormal matrix whose range approximates the range of A.  Parameters 
 
A2D array 

The input data matrix.  
sizeint 

Size of the return array.  
n_iterint 

Number of power iterations used to stabilize the result.  
power_iteration_normalizer{‘auto’, ‘QR’, ‘LU’, ‘none’}, default=’auto’ 

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.   
random_stateint, RandomState instance or None, default=None 

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.    Returns 
 
Qndarray 

A (size x size) projection matrix, the range of which approximates well the range of the input matrix A.     Notes 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
sklearn.utils.extmath.randomized_svd  
sklearn.utils.extmath.randomized_svd(M, n_components, *, n_oversamples=10, n_iter='auto', power_iteration_normalizer='auto', transpose='auto', flip_sign=True, random_state=0) [source]
 
Computes a truncated randomized SVD.  Parameters 
 
M{ndarray, sparse matrix} 

Matrix to decompose.  
n_componentsint 

Number of singular values and vectors to extract.  
n_oversamplesint, default=10 

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.  
n_iterint or ‘auto’, default=’auto’ 

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.   
power_iteration_normalizer{‘auto’, ‘QR’, ‘LU’, ‘none’}, default=’auto’ 

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.   
transposebool or ‘auto’, default=’auto’ 

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.   
flip_signbool, default=True 

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.  
random_stateint, RandomState instance or None, default=0 

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.     Notes 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). References  Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions Halko, et al., 2009 https://arxiv.org/abs/0909.4061
 A randomized algorithm for the decomposition of matrices Per-Gunnar Martinsson, Vladimir Rokhlin and Mark Tygert An implementation of a randomized algorithm for principal component analysis A. Szlam et al. 2014
sklearn.utils.extmath.safe_sparse_dot  
sklearn.utils.extmath.safe_sparse_dot(a, b, *, dense_output=False) [source]
 
Dot product that handle the sparse matrix case correctly.  Parameters 
 
a{ndarray, sparse matrix} 

b{ndarray, sparse matrix} 

dense_outputbool, default=False 

When False, a and b both being sparse will yield sparse output. When True, output will always be a dense array.    Returns 
 
dot_product{ndarray, sparse matrix} 

Sparse if a and b are sparse and dense_output=False.
sklearn.utils.extmath.weighted_mode  
sklearn.utils.extmath.weighted_mode(a, w, *, axis=0) [source]
 
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.  Parameters 
 
aarray-like 

n-dimensional array of which to find mode(s).  
warray-like 

n-dimensional array of weights for each value.  
axisint, default=0 

Axis along which to operate. Default is 0, i.e. the first axis.    Returns 
 
valsndarray 

Array of modal values.  
scorendarray 

Array of weighted counts for each mode.      See also  
scipy.stats.mode

  Examples >>> from sklearn.utils.extmath import weighted_mode
>>> x = [4, 1, 4, 2, 4, 2]
>>> weights = [1, 1, 1, 1, 1, 1]
>>> weighted_mode(x, weights)
(array([4.]), array([3.]))
 The value 4 appears three times: with uniform weights, the result is simply the mode of the distribution. >>> weights = [1, 3, 0.5, 1.5, 1, 2]  # deweight the 4's
>>> weighted_mode(x, weights)
(array([2.]), array([3.5]))
 The value 2 has the highest score: it appears twice with weights of 1.5 and 2: the sum of these is 3.5.
sklearn.utils.gen_even_slices  
sklearn.utils.gen_even_slices(n, n_packs, *, n_samples=None) [source]
 
Generator to create n_packs slices going up to n.  Parameters 
 
nint 

n_packsint 

Number of slices to generate.  
n_samplesint, default=None 

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.    Yields 
 slice
   Examples >>> from sklearn.utils import gen_even_slices
>>> list(gen_even_slices(10, 1))
[slice(0, 10, None)]
>>> list(gen_even_slices(10, 10))
[slice(0, 1, None), slice(1, 2, None), ..., slice(9, 10, None)]
>>> list(gen_even_slices(10, 5))
[slice(0, 2, None), slice(2, 4, None), ..., slice(8, 10, None)]
>>> list(gen_even_slices(10, 3))
[slice(0, 4, None), slice(4, 7, None), slice(7, 10, None)]
 
 Examples using sklearn.utils.gen_even_slices
 
  Poisson regression and non-normal loss
sklearn.utils.graph.single_source_shortest_path_length  
sklearn.utils.graph.single_source_shortest_path_length(graph, source, *, cutoff=None) [source]
 
Return the shortest path length from source to all reachable nodes. Returns a dictionary of shortest path lengths keyed by target.  Parameters 
 
graph{sparse matrix, ndarray} of shape (n, n) 

Adjacency matrix of the graph. Sparse matrix of format LIL is preferred.  
sourceint 

Starting node for path.  
cutoffint, default=None 

Depth to stop the search - only paths of length <= cutoff are returned.     Examples >>> from sklearn.utils.graph import single_source_shortest_path_length
>>> import numpy as np
>>> graph = np.array([[ 0, 1, 0, 0],
...                   [ 1, 0, 1, 0],
...                   [ 0, 1, 0, 1],
...                   [ 0, 0, 1, 0]])
>>> list(sorted(single_source_shortest_path_length(graph, 0).items()))
[(0, 0), (1, 1), (2, 2), (3, 3)]
>>> graph = np.ones((6, 6))
>>> list(sorted(single_source_shortest_path_length(graph, 2).items()))
[(0, 1), (1, 1), (2, 0), (3, 1), (4, 1), (5, 1)]
sklearn.utils.graph_shortest_path.graph_shortest_path  
sklearn.utils.graph_shortest_path.graph_shortest_path()  
Perform a shortest-path graph search on a positive directed or undirected graph.  Parameters 
 
dist_matrixarraylike or sparse matrix, shape = (N,N) 

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  
directedboolean 

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.  
methodstring [‘auto’|’FW’|’D’] 

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]    Returns 
 
Gnp.ndarray, float, shape = [N,N] 

G[i,j] gives the shortest distance from point i to point j along the graph.     Notes 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.
sklearn.utils.indexable  
sklearn.utils.indexable(*iterables) [source]
 
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.  Parameters 
 
*iterables{lists, dataframes, ndarrays, sparse matrices} 

List of objects to ensure sliceability.
sklearn.utils.metaestimators.if_delegate_has_method  
sklearn.utils.metaestimators.if_delegate_has_method(delegate) [source]
 
Create a decorator for methods that are delegated to a sub-estimator This enables ducktyping by hasattr returning True according to the sub-estimator.  Parameters 
 
delegatestring, list of strings or tuple of strings 

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.     
 Examples using sklearn.utils.metaestimators.if_delegate_has_method
 
  Inductive Clustering
sklearn.utils.multiclass.is_multilabel  
sklearn.utils.multiclass.is_multilabel(y) [source]
 
Check if y is in a multilabel format.  Parameters 
 
yndarray of shape (n_samples,) 

Target values.    Returns 
 
outbool 

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
sklearn.utils.multiclass.type_of_target  
sklearn.utils.multiclass.type_of_target(y) [source]
 
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 
 
yarray-like 
  Returns 
 
target_typestr 

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'
sklearn.utils.multiclass.unique_labels  
sklearn.utils.multiclass.unique_labels(*ys) [source]
 
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 
 
*ysarray-likes 
  Returns 
 
outndarray 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])
sklearn.utils.murmurhash3_32  
sklearn.utils.murmurhash3_32()  
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.  Parameters 
 
keynp.int32, bytes, unicode or ndarray of dtype=np.int32 

The physical object to hash.  
seedint, default=0 

Integer seed for the hashing algorithm.  
positivebool, default=False 

 True: the results is casted to an unsigned int

from 0 to 2 ** 32 - 1  False: the results is casted to a signed int

from -(2 ** 31) to 2 ** 31 - 1
sklearn.utils.parallel_backend  
sklearn.utils.parallel_backend(backend, n_jobs=- 1, inner_max_num_threads=None, **backend_params) [source]
 
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’: single-host, process-based parallelism (used by default), ‘threading’: single-host, thread-based parallelism, ‘multiprocessing’: legacy single-host, process-based parallelism.  ‘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: >>> from ray.util.joblib import register_ray  
>>> register_ray()  
>>> with parallel_backend("ray"):  
...     print(Parallel()(delayed(neg)(i + 1) for i in range(5)))
[-1, -2, -3, -4, -5]
 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. >>> from operator import neg
>>> with parallel_backend('threading'):
...     print(Parallel()(delayed(neg)(i + 1) for i in range(5)))
...
[-1, -2, -3, -4, -5]
 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.
sklearn.utils.random.sample_without_replacement  
sklearn.utils.random.sample_without_replacement()  
Sample integers without replacement. Select n_samples integers from the set [0, n_population) without replacement.  Parameters 
 
n_populationint 

The size of the set to sample from.  
n_samplesint 

The number of integer to sample.  
random_stateint, RandomState instance or None, default=None 

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.  
method{“auto”, “tracking_selection”, “reservoir_sampling”, “pool”}, default=’auto’ 

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.    Returns 
 
outndarray of shape (n_samples,) 

The sampled subsets of integer. The subset of selected integer might not be randomized, see the method argument.
sklearn.utils.register_parallel_backend  
sklearn.utils.register_parallel_backend(name, factory, make_default=False) [source]
 
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.