code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def _pkl_filepath(*args, **kwargs): """Return filename for Python 3 pickles args[-1] is expected to be the ".pkl" filename. For compatibility with older scikit-learn versions, a suffix is inserted before the extension. _pkl_filepath('/path/to/folder', 'filename.pkl') returns '/path/to/folder/filen...
Return filename for Python 3 pickles args[-1] is expected to be the ".pkl" filename. For compatibility with older scikit-learn versions, a suffix is inserted before the extension. _pkl_filepath('/path/to/folder', 'filename.pkl') returns '/path/to/folder/filename_py3.pkl'
_pkl_filepath
python
scikit-learn/scikit-learn
sklearn/datasets/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_base.py
BSD-3-Clause
def _sha256(path): """Calculate the sha256 hash of the file at path.""" sha256hash = hashlib.sha256() chunk_size = 8192 with open(path, "rb") as f: while True: buffer = f.read(chunk_size) if not buffer: break sha256hash.update(buffer) retur...
Calculate the sha256 hash of the file at path.
_sha256
python
scikit-learn/scikit-learn
sklearn/datasets/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_base.py
BSD-3-Clause
def _fetch_remote(remote, dirname=None, n_retries=3, delay=1): """Helper function to download a remote dataset. Fetch a dataset pointed by remote's url, save into path using remote's filename and ensure its integrity based on the SHA256 checksum of the downloaded file. .. versionchanged:: 1.6 ...
Helper function to download a remote dataset. Fetch a dataset pointed by remote's url, save into path using remote's filename and ensure its integrity based on the SHA256 checksum of the downloaded file. .. versionchanged:: 1.6 If the file already exists locally and the SHA256 checksums match...
_fetch_remote
python
scikit-learn/scikit-learn
sklearn/datasets/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_base.py
BSD-3-Clause
def _filter_filename(value, filter_dots=True): """Derive a name that is safe to use as filename from the given string. Adapted from the `slugify` function of django: https://github.com/django/django/blob/master/django/utils/text.py Convert spaces or repeated dashes to single dashes. Replace characters...
Derive a name that is safe to use as filename from the given string. Adapted from the `slugify` function of django: https://github.com/django/django/blob/master/django/utils/text.py Convert spaces or repeated dashes to single dashes. Replace characters that aren't alphanumerics, underscores, hyphens o...
_filter_filename
python
scikit-learn/scikit-learn
sklearn/datasets/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_base.py
BSD-3-Clause
def fetch_file( url, folder=None, local_filename=None, sha256=None, n_retries=3, delay=1 ): """Fetch a file from the web if not already present in the local folder. If the file already exists locally (and the SHA256 checksums match when provided), the path to the local file is returned without re-downl...
Fetch a file from the web if not already present in the local folder. If the file already exists locally (and the SHA256 checksums match when provided), the path to the local file is returned without re-downloading. .. versionadded:: 1.6 Parameters ---------- url : str URL of the file...
fetch_file
python
scikit-learn/scikit-learn
sklearn/datasets/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_base.py
BSD-3-Clause
def fetch_california_housing( *, data_home=None, download_if_missing=True, return_X_y=False, as_frame=False, n_retries=3, delay=1.0, ): """Load the California housing dataset (regression). ============== ============== Samples total 20640 Dimensionality ...
Load the California housing dataset (regression). ============== ============== Samples total 20640 Dimensionality 8 Features real Target real 0.15 - 5. ============== ============== Read more in the :ref:`User Guide <california_ho...
fetch_california_housing
python
scikit-learn/scikit-learn
sklearn/datasets/_california_housing.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_california_housing.py
BSD-3-Clause
def fetch_covtype( *, data_home=None, download_if_missing=True, random_state=None, shuffle=False, return_X_y=False, as_frame=False, n_retries=3, delay=1.0, ): """Load the covertype dataset (classification). Download it if necessary. ================= ============ ...
Load the covertype dataset (classification). Download it if necessary. ================= ============ Classes 7 Samples total 581012 Dimensionality 54 Features int ================= ============ Read more in the...
fetch_covtype
python
scikit-learn/scikit-learn
sklearn/datasets/_covtype.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_covtype.py
BSD-3-Clause
def fetch_kddcup99( *, subset=None, data_home=None, shuffle=False, random_state=None, percent10=True, download_if_missing=True, return_X_y=False, as_frame=False, n_retries=3, delay=1.0, ): """Load the kddcup99 dataset (classification). Download it if necessary. ...
Load the kddcup99 dataset (classification). Download it if necessary. ================= ==================================== Classes 23 Samples total 4898431 Dimensionality 41 ...
fetch_kddcup99
python
scikit-learn/scikit-learn
sklearn/datasets/_kddcup99.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_kddcup99.py
BSD-3-Clause
def _fetch_brute_kddcup99( data_home=None, download_if_missing=True, percent10=True, n_retries=3, delay=1.0 ): """Load the kddcup99 dataset, downloading it if necessary. Parameters ---------- data_home : str, default=None Specify another download and cache folder for the datasets. By defaul...
Load the kddcup99 dataset, downloading it if necessary. Parameters ---------- data_home : str, default=None Specify another download and cache folder for the datasets. By default all scikit-learn data is stored in '~/scikit_learn_data' subfolders. download_if_missing : bool, default=Tr...
_fetch_brute_kddcup99
python
scikit-learn/scikit-learn
sklearn/datasets/_kddcup99.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_kddcup99.py
BSD-3-Clause
def _mkdirp(d): """Ensure directory d exists (like mkdir -p on Unix) No guarantee that the directory is writable. """ try: os.makedirs(d) except OSError as e: if e.errno != errno.EEXIST: raise
Ensure directory d exists (like mkdir -p on Unix) No guarantee that the directory is writable.
_mkdirp
python
scikit-learn/scikit-learn
sklearn/datasets/_kddcup99.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_kddcup99.py
BSD-3-Clause
def _check_fetch_lfw( data_home=None, funneled=True, download_if_missing=True, n_retries=3, delay=1.0 ): """Helper function to download any missing LFW data""" data_home = get_data_home(data_home=data_home) lfw_home = join(data_home, "lfw_home") if not exists(lfw_home): makedirs(lfw_home) ...
Helper function to download any missing LFW data
_check_fetch_lfw
python
scikit-learn/scikit-learn
sklearn/datasets/_lfw.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_lfw.py
BSD-3-Clause
def _fetch_lfw_people( data_folder_path, slice_=None, color=False, resize=None, min_faces_per_person=0 ): """Perform the actual data loading for the lfw people dataset This operation is meant to be cached by a joblib wrapper. """ # scan the data folder content to retain people with more that # ...
Perform the actual data loading for the lfw people dataset This operation is meant to be cached by a joblib wrapper.
_fetch_lfw_people
python
scikit-learn/scikit-learn
sklearn/datasets/_lfw.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_lfw.py
BSD-3-Clause
def fetch_lfw_people( *, data_home=None, funneled=True, resize=0.5, min_faces_per_person=0, color=False, slice_=(slice(70, 195), slice(78, 172)), download_if_missing=True, return_X_y=False, n_retries=3, delay=1.0, ): """Load the Labeled Faces in the Wild (LFW) people data...
Load the Labeled Faces in the Wild (LFW) people dataset (classification). Download it if necessary. ================= ======================= Classes 5749 Samples total 13233 Dimensionality 5828 Features ...
fetch_lfw_people
python
scikit-learn/scikit-learn
sklearn/datasets/_lfw.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_lfw.py
BSD-3-Clause
def _fetch_lfw_pairs( index_file_path, data_folder_path, slice_=None, color=False, resize=None ): """Perform the actual data loading for the LFW pairs dataset This operation is meant to be cached by a joblib wrapper. """ # parse the index file to find the number of pairs to be able to allocate ...
Perform the actual data loading for the LFW pairs dataset This operation is meant to be cached by a joblib wrapper.
_fetch_lfw_pairs
python
scikit-learn/scikit-learn
sklearn/datasets/_lfw.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_lfw.py
BSD-3-Clause
def fetch_lfw_pairs( *, subset="train", data_home=None, funneled=True, resize=0.5, color=False, slice_=(slice(70, 195), slice(78, 172)), download_if_missing=True, n_retries=3, delay=1.0, ): """Load the Labeled Faces in the Wild (LFW) pairs dataset (classification). Downl...
Load the Labeled Faces in the Wild (LFW) pairs dataset (classification). Download it if necessary. ================= ======================= Classes 2 Samples total 13233 Dimensionality 5828 Features ...
fetch_lfw_pairs
python
scikit-learn/scikit-learn
sklearn/datasets/_lfw.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_lfw.py
BSD-3-Clause
def fetch_olivetti_faces( *, data_home=None, shuffle=False, random_state=0, download_if_missing=True, return_X_y=False, n_retries=3, delay=1.0, ): """Load the Olivetti faces data-set from AT&T (classification). Download it if necessary. ================= =================...
Load the Olivetti faces data-set from AT&T (classification). Download it if necessary. ================= ===================== Classes 40 Samples total 400 Dimensionality 4096 Features real, between 0 and...
fetch_olivetti_faces
python
scikit-learn/scikit-learn
sklearn/datasets/_olivetti_faces.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_olivetti_faces.py
BSD-3-Clause
def _retry_with_clean_cache( openml_path: str, data_home: Optional[str], no_retry_exception: Optional[Exception] = None, ) -> Callable: """If the first call to the decorated function fails, the local cached file is removed, and the function is called again. If ``data_home`` is ``None``, then the...
If the first call to the decorated function fails, the local cached file is removed, and the function is called again. If ``data_home`` is ``None``, then the function is called once. We can provide a specific exception to not retry on using `no_retry_exception` parameter.
_retry_with_clean_cache
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def _retry_on_network_error( n_retries: int = 3, delay: float = 1.0, url: str = "" ) -> Callable: """If the function call results in a network error, call the function again up to ``n_retries`` times with a ``delay`` between each call. If the error has a 412 status code, don't call the function again as...
If the function call results in a network error, call the function again up to ``n_retries`` times with a ``delay`` between each call. If the error has a 412 status code, don't call the function again as this is a specific OpenML error. The url parameter is used to give more information to the user abou...
_retry_on_network_error
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def _open_openml_url( url: str, data_home: Optional[str], n_retries: int = 3, delay: float = 1.0 ): """ Returns a resource from OpenML.org. Caches it to data_home if required. Parameters ---------- url : str OpenML URL that will be downloaded and cached locally. The path component ...
Returns a resource from OpenML.org. Caches it to data_home if required. Parameters ---------- url : str OpenML URL that will be downloaded and cached locally. The path component of the URL is used to replicate the tree structure as sub-folders of the local cache folder. da...
_open_openml_url
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def _get_json_content_from_openml_api( url: str, error_message: Optional[str], data_home: Optional[str], n_retries: int = 3, delay: float = 1.0, ) -> Dict: """ Loads json data from the openml api. Parameters ---------- url : str The URL to load from. Should be an officia...
Loads json data from the openml api. Parameters ---------- url : str The URL to load from. Should be an official OpenML endpoint. error_message : str or None The error message to raise if an acceptable OpenML error is thrown (acceptable error is, e.g., data id not found. O...
_get_json_content_from_openml_api
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def _get_data_info_by_name( name: str, version: Union[int, str], data_home: Optional[str], n_retries: int = 3, delay: float = 1.0, ): """ Utilizes the openml dataset listing api to find a dataset by name/version OpenML api function: https://www.openml.org/api_docs#!/data/get_data...
Utilizes the openml dataset listing api to find a dataset by name/version OpenML api function: https://www.openml.org/api_docs#!/data/get_data_list_data_name_data_name Parameters ---------- name : str name of the dataset version : int or str If version is an integer, t...
_get_data_info_by_name
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def _get_num_samples(data_qualities: OpenmlQualitiesType) -> int: """Get the number of samples from data qualities. Parameters ---------- data_qualities : list of dict Used to retrieve the number of instances (samples) in the dataset. Returns ------- n_samples : int The num...
Get the number of samples from data qualities. Parameters ---------- data_qualities : list of dict Used to retrieve the number of instances (samples) in the dataset. Returns ------- n_samples : int The number of samples in the dataset or -1 if data qualities are unavail...
_get_num_samples
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def _load_arff_response( url: str, data_home: Optional[str], parser: str, output_type: str, openml_columns_info: dict, feature_names_to_select: List[str], target_names_to_select: List[str], shape: Optional[Tuple[int, int]], md5_checksum: str, n_retries: int = 3, delay: float ...
Load the ARFF data associated with the OpenML URL. In addition of loading the data, this function will also check the integrity of the downloaded file from OpenML using MD5 checksum. Parameters ---------- url : str The URL of the ARFF file on OpenML. data_home : str The locati...
_load_arff_response
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def _download_data_to_bunch( url: str, sparse: bool, data_home: Optional[str], *, as_frame: bool, openml_columns_info: List[dict], data_columns: List[str], target_columns: List[str], shape: Optional[Tuple[int, int]], md5_checksum: str, n_retries: int = 3, delay: float = 1...
Download ARFF data, load it to a specific container and create to Bunch. This function has a mechanism to retry/cache/clean the data. Parameters ---------- url : str The URL of the ARFF file on OpenML. sparse : bool Whether the dataset is expected to use the sparse ARFF format. ...
_download_data_to_bunch
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def fetch_openml( name: Optional[str] = None, *, version: Union[str, int] = "active", data_id: Optional[int] = None, data_home: Optional[Union[str, os.PathLike]] = None, target_column: Optional[Union[str, List]] = "default-target", cache: bool = True, return_X_y: bool = False, as_fra...
Fetch dataset from openml by name or dataset id. Datasets are uniquely identified by either an integer ID or by a combination of name and version (i.e. there might be multiple versions of the 'iris' dataset). Please give either name or data_id (not both). In case a name is given, a version can also be ...
fetch_openml
python
scikit-learn/scikit-learn
sklearn/datasets/_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_openml.py
BSD-3-Clause
def fetch_rcv1( *, data_home=None, subset="all", download_if_missing=True, random_state=None, shuffle=False, return_X_y=False, n_retries=3, delay=1.0, ): """Load the RCV1 multilabel dataset (classification). Download it if necessary. Version: RCV1-v2, vectors, full sets...
Load the RCV1 multilabel dataset (classification). Download it if necessary. Version: RCV1-v2, vectors, full sets, topics multilabels. ================= ===================== Classes 103 Samples total 804414 Dimensionality ...
fetch_rcv1
python
scikit-learn/scikit-learn
sklearn/datasets/_rcv1.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_rcv1.py
BSD-3-Clause
def _generate_hypercube(samples, dimensions, rng): """Returns distinct binary samples of length dimensions.""" if dimensions > 30: return np.hstack( [ rng.randint(2, size=(samples, dimensions - 30)), _generate_hypercube(samples, 30, rng), ] ...
Returns distinct binary samples of length dimensions.
_generate_hypercube
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_classification( n_samples=100, n_features=20, *, n_informative=2, n_redundant=2, n_repeated=0, n_classes=2, n_clusters_per_class=2, weights=None, flip_y=0.01, class_sep=1.0, hypercube=True, shift=0.0, scale=1.0, shuffle=True, random_state=None, ...
Generate a random n-class classification problem. This initially creates clusters of points normally distributed (std=1) about vertices of an ``n_informative``-dimensional hypercube with sides of length ``2*class_sep`` and assigns an equal number of clusters to each class. It introduces interdependence...
make_classification
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_multilabel_classification( n_samples=100, n_features=20, *, n_classes=5, n_labels=2, length=50, allow_unlabeled=True, sparse=False, return_indicator="dense", return_distributions=False, random_state=None, ): """Generate a random multilabel classification problem....
Generate a random multilabel classification problem. For each sample, the generative process is: - pick the number of labels: n ~ Poisson(n_labels) - n times, choose a class c: c ~ Multinomial(theta) - pick the document length: k ~ Poisson(length) - k times, choose a word: w ~ Multi...
make_multilabel_classification
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_hastie_10_2(n_samples=12000, *, random_state=None): """Generate data for binary classification used in Hastie et al. 2009, Example 10.2. The ten features are standard independent Gaussian and the target ``y`` is defined by:: y[i] = 1 if np.sum(X[i] ** 2) > 9.34 else -1 Read more in the...
Generate data for binary classification used in Hastie et al. 2009, Example 10.2. The ten features are standard independent Gaussian and the target ``y`` is defined by:: y[i] = 1 if np.sum(X[i] ** 2) > 9.34 else -1 Read more in the :ref:`User Guide <sample_generators>`. Parameters --------...
make_hastie_10_2
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_regression( n_samples=100, n_features=100, *, n_informative=10, n_targets=1, bias=0.0, effective_rank=None, tail_strength=0.5, noise=0.0, shuffle=True, coef=False, random_state=None, ): """Generate a random regression problem. The input set can either be...
Generate a random regression problem. The input set can either be well conditioned (by default) or have a low rank-fat tail singular profile. See :func:`make_low_rank_matrix` for more details. The output is generated by applying a (potentially biased) random linear regression model with `n_informa...
make_regression
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_circles( n_samples=100, *, shuffle=True, noise=None, random_state=None, factor=0.8 ): """Make a large circle containing a smaller circle in 2d. A simple toy dataset to visualize clustering and classification algorithms. Read more in the :ref:`User Guide <sample_generators>`. Paramete...
Make a large circle containing a smaller circle in 2d. A simple toy dataset to visualize clustering and classification algorithms. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_samples : int or tuple of shape (2,), dtype=int, default=100 If int, it is...
make_circles
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_moons(n_samples=100, *, shuffle=True, noise=None, random_state=None): """Make two interleaving half circles. A simple toy dataset to visualize clustering and classification algorithms. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_samples : int or tup...
Make two interleaving half circles. A simple toy dataset to visualize clustering and classification algorithms. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_samples : int or tuple of shape (2,), dtype=int, default=100 If int, the total number of points ge...
make_moons
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_blobs( n_samples=100, n_features=2, *, centers=None, cluster_std=1.0, center_box=(-10.0, 10.0), shuffle=True, random_state=None, return_centers=False, ): """Generate isotropic Gaussian blobs for clustering. Read more in the :ref:`User Guide <sample_generators>`. ...
Generate isotropic Gaussian blobs for clustering. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_samples : int or array-like, default=100 If int, it is the total number of points equally divided among clusters. If array-like, each element of the...
make_blobs
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_friedman1(n_samples=100, n_features=10, *, noise=0.0, random_state=None): """Generate the "Friedman #1" regression problem. This dataset is described in Friedman [1] and Breiman [2]. Inputs `X` are independent features uniformly distributed on the interval [0, 1]. The output `y` is created ac...
Generate the "Friedman #1" regression problem. This dataset is described in Friedman [1] and Breiman [2]. Inputs `X` are independent features uniformly distributed on the interval [0, 1]. The output `y` is created according to the formula:: y(X) = 10 * sin(pi * X[:, 0] * X[:, 1]) + 20 * (X[:, 2] ...
make_friedman1
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_friedman2(n_samples=100, *, noise=0.0, random_state=None): """Generate the "Friedman #2" regression problem. This dataset is described in Friedman [1] and Breiman [2]. Inputs `X` are 4 independent features uniformly distributed on the intervals:: 0 <= X[:, 0] <= 100, 40 * pi ...
Generate the "Friedman #2" regression problem. This dataset is described in Friedman [1] and Breiman [2]. Inputs `X` are 4 independent features uniformly distributed on the intervals:: 0 <= X[:, 0] <= 100, 40 * pi <= X[:, 1] <= 560 * pi, 0 <= X[:, 2] <= 1, 1 <= X[:, 3] <= ...
make_friedman2
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_friedman3(n_samples=100, *, noise=0.0, random_state=None): """Generate the "Friedman #3" regression problem. This dataset is described in Friedman [1] and Breiman [2]. Inputs `X` are 4 independent features uniformly distributed on the intervals:: 0 <= X[:, 0] <= 100, 40 * pi ...
Generate the "Friedman #3" regression problem. This dataset is described in Friedman [1] and Breiman [2]. Inputs `X` are 4 independent features uniformly distributed on the intervals:: 0 <= X[:, 0] <= 100, 40 * pi <= X[:, 1] <= 560 * pi, 0 <= X[:, 2] <= 1, 1 <= X[:, 3] <= ...
make_friedman3
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_low_rank_matrix( n_samples=100, n_features=100, *, effective_rank=10, tail_strength=0.5, random_state=None, ): """Generate a mostly low rank matrix with bell-shaped singular values. Most of the variance can be explained by a bell-shaped curve of width effective_rank: the lo...
Generate a mostly low rank matrix with bell-shaped singular values. Most of the variance can be explained by a bell-shaped curve of width effective_rank: the low rank part of the singular values profile is:: (1 - tail_strength) * exp(-1.0 * (i / effective_rank) ** 2) The remaining singular values...
make_low_rank_matrix
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_sparse_coded_signal( n_samples, *, n_components, n_features, n_nonzero_coefs, random_state=None, ): """Generate a signal as a sparse combination of dictionary elements. Returns matrices `Y`, `D` and `X` such that `Y = XD` where `X` is of shape `(n_samples, n_components)`, `...
Generate a signal as a sparse combination of dictionary elements. Returns matrices `Y`, `D` and `X` such that `Y = XD` where `X` is of shape `(n_samples, n_components)`, `D` is of shape `(n_components, n_features)`, and each row of `X` has exactly `n_nonzero_coefs` non-zero elements. Read more in the ...
make_sparse_coded_signal
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_sparse_uncorrelated(n_samples=100, n_features=10, *, random_state=None): """Generate a random regression problem with sparse uncorrelated design. This dataset is described in Celeux et al [1]. as:: X ~ N(0, 1) y(X) = X[:, 0] + 2 * X[:, 1] - 2 * X[:, 2] - 1.5 * X[:, 3] Only the fi...
Generate a random regression problem with sparse uncorrelated design. This dataset is described in Celeux et al [1]. as:: X ~ N(0, 1) y(X) = X[:, 0] + 2 * X[:, 1] - 2 * X[:, 2] - 1.5 * X[:, 3] Only the first 4 features are informative. The remaining features are useless. Read more in...
make_sparse_uncorrelated
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_spd_matrix(n_dim, *, random_state=None): """Generate a random symmetric, positive-definite matrix. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_dim : int The matrix dimension. random_state : int, RandomState instance or None, default=None ...
Generate a random symmetric, positive-definite matrix. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_dim : int The matrix dimension. random_state : int, RandomState instance or None, default=None Determines random number generation for dataset cre...
make_spd_matrix
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_sparse_spd_matrix( n_dim=1, *, alpha=0.95, norm_diag=False, smallest_coef=0.1, largest_coef=0.9, sparse_format=None, random_state=None, ): """Generate a sparse symmetric definite positive matrix. Read more in the :ref:`User Guide <sample_generators>`. Parameters ...
Generate a sparse symmetric definite positive matrix. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_dim : int, default=1 The size of the random matrix to generate. .. versionchanged:: 1.4 Renamed from ``dim`` to ``n_dim``. alpha : flo...
make_sparse_spd_matrix
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_swiss_roll(n_samples=100, *, noise=0.0, random_state=None, hole=False): """Generate a swiss roll dataset. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_samples : int, default=100 The number of sample points on the Swiss Roll. noise : float, d...
Generate a swiss roll dataset. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_samples : int, default=100 The number of sample points on the Swiss Roll. noise : float, default=0.0 The standard deviation of the gaussian noise. random_state : int...
make_swiss_roll
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_s_curve(n_samples=100, *, noise=0.0, random_state=None): """Generate an S curve dataset. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_samples : int, default=100 The number of sample points on the S curve. noise : float, default=0.0 T...
Generate an S curve dataset. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- n_samples : int, default=100 The number of sample points on the S curve. noise : float, default=0.0 The standard deviation of the gaussian noise. random_state : int, Ran...
make_s_curve
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_gaussian_quantiles( *, mean=None, cov=1.0, n_samples=100, n_features=2, n_classes=3, shuffle=True, random_state=None, ): r"""Generate isotropic Gaussian and label samples by quantile. This classification dataset is constructed by taking a multi-dimensional standard ...
Generate isotropic Gaussian and label samples by quantile. This classification dataset is constructed by taking a multi-dimensional standard normal distribution and defining classes separated by nested concentric multi-dimensional spheres such that roughly equal numbers of samples are in each class (qu...
make_gaussian_quantiles
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_biclusters( shape, n_clusters, *, noise=0.0, minval=10, maxval=100, shuffle=True, random_state=None, ): """Generate a constant block diagonal structure array for biclustering. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- sha...
Generate a constant block diagonal structure array for biclustering. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- shape : tuple of shape (n_rows, n_cols) The shape of the result. n_clusters : int The number of biclusters. noise : float, defaul...
make_biclusters
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def make_checkerboard( shape, n_clusters, *, noise=0.0, minval=10, maxval=100, shuffle=True, random_state=None, ): """Generate an array with block checkerboard structure for biclustering. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- ...
Generate an array with block checkerboard structure for biclustering. Read more in the :ref:`User Guide <sample_generators>`. Parameters ---------- shape : tuple of shape (n_rows, n_cols) The shape of the result. n_clusters : int or array-like or shape (n_row_clusters, n_column_clusters) ...
make_checkerboard
python
scikit-learn/scikit-learn
sklearn/datasets/_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_samples_generator.py
BSD-3-Clause
def _load_coverage(F, header_length=6, dtype=np.int16): """Load a coverage file from an open file object. This will return a numpy array of the given dtype """ header = [F.readline() for _ in range(header_length)] make_tuple = lambda t: (t.split()[0], float(t.split()[1])) header = dict([make_tu...
Load a coverage file from an open file object. This will return a numpy array of the given dtype
_load_coverage
python
scikit-learn/scikit-learn
sklearn/datasets/_species_distributions.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_species_distributions.py
BSD-3-Clause
def _load_csv(F): """Load csv file. Parameters ---------- F : file object CSV file open in byte mode. Returns ------- rec : np.ndarray record array representing the data """ names = F.readline().decode("ascii").strip().split(",") rec = np.loadtxt(F, skiprows=0,...
Load csv file. Parameters ---------- F : file object CSV file open in byte mode. Returns ------- rec : np.ndarray record array representing the data
_load_csv
python
scikit-learn/scikit-learn
sklearn/datasets/_species_distributions.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_species_distributions.py
BSD-3-Clause
def fetch_species_distributions( *, data_home=None, download_if_missing=True, n_retries=3, delay=1.0, ): """Loader for species distribution dataset from Phillips et. al. (2006). Read more in the :ref:`User Guide <species_distribution_dataset>`. Parameters ---------- data_home :...
Loader for species distribution dataset from Phillips et. al. (2006). Read more in the :ref:`User Guide <species_distribution_dataset>`. Parameters ---------- data_home : str or path-like, default=None Specify another download and cache folder for the datasets. By default all scikit-le...
fetch_species_distributions
python
scikit-learn/scikit-learn
sklearn/datasets/_species_distributions.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_species_distributions.py
BSD-3-Clause
def load_svmlight_file( f, *, n_features=None, dtype=np.float64, multilabel=False, zero_based="auto", query_id=False, offset=0, length=-1, ): """Load datasets in the svmlight / libsvm format into sparse CSR matrix. This format is a text-based format, with one sample per line...
Load datasets in the svmlight / libsvm format into sparse CSR matrix. This format is a text-based format, with one sample per line. It does not store zero valued features hence is suitable for sparse dataset. The first element of each line can be used to store a target variable to predict. This f...
load_svmlight_file
python
scikit-learn/scikit-learn
sklearn/datasets/_svmlight_format_io.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_svmlight_format_io.py
BSD-3-Clause
def load_svmlight_files( files, *, n_features=None, dtype=np.float64, multilabel=False, zero_based="auto", query_id=False, offset=0, length=-1, ): """Load dataset from multiple files in SVMlight format. This function is equivalent to mapping load_svmlight_file over a list of...
Load dataset from multiple files in SVMlight format. This function is equivalent to mapping load_svmlight_file over a list of files, except that the results are concatenated into a single, flat list and the samples vectors are constrained to all have the same number of features. In case the file c...
load_svmlight_files
python
scikit-learn/scikit-learn
sklearn/datasets/_svmlight_format_io.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_svmlight_format_io.py
BSD-3-Clause
def dump_svmlight_file( X, y, f, *, zero_based=True, comment=None, query_id=None, multilabel=False, ): """Dump the dataset in svmlight / libsvm file format. This format is a text-based format, with one sample per line. It does not store zero valued features hence is suitable...
Dump the dataset in svmlight / libsvm file format. This format is a text-based format, with one sample per line. It does not store zero valued features hence is suitable for sparse dataset. The first element of each line can be used to store a target variable to predict. Parameters ----------...
dump_svmlight_file
python
scikit-learn/scikit-learn
sklearn/datasets/_svmlight_format_io.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_svmlight_format_io.py
BSD-3-Clause
def _download_20newsgroups(target_dir, cache_path, n_retries, delay): """Download the 20 newsgroups data and stored it as a zipped pickle.""" train_path = os.path.join(target_dir, TRAIN_FOLDER) test_path = os.path.join(target_dir, TEST_FOLDER) os.makedirs(target_dir, exist_ok=True) logger.info("Do...
Download the 20 newsgroups data and stored it as a zipped pickle.
_download_20newsgroups
python
scikit-learn/scikit-learn
sklearn/datasets/_twenty_newsgroups.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_twenty_newsgroups.py
BSD-3-Clause
def strip_newsgroup_footer(text): """ Given text in "news" format, attempt to remove a signature block. As a rough heuristic, we assume that signatures are set apart by either a blank line or a line made of hyphens, and that it is the last such line in the file (disregarding blank lines at the end)...
Given text in "news" format, attempt to remove a signature block. As a rough heuristic, we assume that signatures are set apart by either a blank line or a line made of hyphens, and that it is the last such line in the file (disregarding blank lines at the end). Parameters ---------- text...
strip_newsgroup_footer
python
scikit-learn/scikit-learn
sklearn/datasets/_twenty_newsgroups.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_twenty_newsgroups.py
BSD-3-Clause
def fetch_20newsgroups( *, data_home=None, subset="train", categories=None, shuffle=True, random_state=42, remove=(), download_if_missing=True, return_X_y=False, n_retries=3, delay=1.0, ): """Load the filenames and data from the 20 newsgroups dataset \ (classification). ...
Load the filenames and data from the 20 newsgroups dataset (classification). Download it if necessary. ================= ========== Classes 20 Samples total 18846 Dimensionality 1 Features text ================= ========== ...
fetch_20newsgroups
python
scikit-learn/scikit-learn
sklearn/datasets/_twenty_newsgroups.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_twenty_newsgroups.py
BSD-3-Clause
def fetch_20newsgroups_vectorized( *, subset="train", remove=(), data_home=None, download_if_missing=True, return_X_y=False, normalize=True, as_frame=False, n_retries=3, delay=1.0, ): """Load and vectorize the 20 newsgroups dataset (classification). Download it if necess...
Load and vectorize the 20 newsgroups dataset (classification). Download it if necessary. This is a convenience function; the transformation is done using the default settings for :class:`~sklearn.feature_extraction.text.CountVectorizer`. For more advanced usage (stopword filtering, n-gram extracti...
fetch_20newsgroups_vectorized
python
scikit-learn/scikit-learn
sklearn/datasets/_twenty_newsgroups.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/_twenty_newsgroups.py
BSD-3-Clause
def test_20news_length_consistency(fetch_20newsgroups_fxt): """Checks the length consistencies within the bunch This is a non-regression test for a bug present in 0.16.1. """ # Extract the full dataset data = fetch_20newsgroups_fxt(subset="all") assert len(data["data"]) == len(data.data) as...
Checks the length consistencies within the bunch This is a non-regression test for a bug present in 0.16.1.
test_20news_length_consistency
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_20news.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_20news.py
BSD-3-Clause
def test_post_process_frame(feature_names, target_names): """Check the behaviour of the post-processing function for splitting a dataframe.""" pd = pytest.importorskip("pandas") X_original = pd.DataFrame( { "col_int_as_integer": [1, 2, 3], "col_int_as_numeric": [1, 2, 3], ...
Check the behaviour of the post-processing function for splitting a dataframe.
test_post_process_frame
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_arff_parser.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_arff_parser.py
BSD-3-Clause
def test_load_arff_from_gzip_file_error_parser(): """An error will be raised if the parser is not known.""" # None of the input parameters are required to be accurate since the check # of the parser will be carried out first. err_msg = "Unknown parser: 'xxx'. Should be 'liac-arff' or 'pandas'" with...
An error will be raised if the parser is not known.
test_load_arff_from_gzip_file_error_parser
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_arff_parser.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_arff_parser.py
BSD-3-Clause
def test_pandas_arff_parser_strip_single_quotes(parser_func): """Check that we properly strip single quotes from the data.""" pd = pytest.importorskip("pandas") arff_file = BytesIO( textwrap.dedent( """ @relation 'toy' @attribute 'cat_single_quote' {'A', 'B', 'C'...
Check that we properly strip single quotes from the data.
test_pandas_arff_parser_strip_single_quotes
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_arff_parser.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_arff_parser.py
BSD-3-Clause
def test_pandas_arff_parser_strip_double_quotes(parser_func): """Check that we properly strip double quotes from the data.""" pd = pytest.importorskip("pandas") arff_file = BytesIO( textwrap.dedent( """ @relation 'toy' @attribute 'cat_double_quote' {"A", "B", "C"...
Check that we properly strip double quotes from the data.
test_pandas_arff_parser_strip_double_quotes
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_arff_parser.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_arff_parser.py
BSD-3-Clause
def test_pandas_arff_parser_strip_no_quotes(parser_func): """Check that we properly parse with no quotes characters.""" pd = pytest.importorskip("pandas") arff_file = BytesIO( textwrap.dedent( """ @relation 'toy' @attribute 'cat_without_quote' {A, B, C} ...
Check that we properly parse with no quotes characters.
test_pandas_arff_parser_strip_no_quotes
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_arff_parser.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_arff_parser.py
BSD-3-Clause
def test_load_diabetes_raw(): """Test to check that we load a scaled version by default but that we can get an unscaled version when setting `scaled=False`.""" diabetes_raw = load_diabetes(scaled=False) assert diabetes_raw.data.shape == (442, 10) assert diabetes_raw.target.size == 442 assert len...
Test to check that we load a scaled version by default but that we can get an unscaled version when setting `scaled=False`.
test_load_diabetes_raw
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_base.py
BSD-3-Clause
def test_load_boston_error(): """Check that we raise the ethical warning when trying to import `load_boston`.""" msg = "The Boston housing prices dataset has an ethical problem" with pytest.raises(ImportError, match=msg): from sklearn.datasets import load_boston # noqa: F401 # other non-existi...
Check that we raise the ethical warning when trying to import `load_boston`.
test_load_boston_error
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_base.py
BSD-3-Clause
def test_corrupted_file_error_message(fetch_kddcup99_fxt, tmp_path): """Check that a nice error message is raised when cache is corrupted.""" kddcup99_dir = tmp_path / "kddcup99_10-py3" kddcup99_dir.mkdir() samples_path = kddcup99_dir / "samples" with samples_path.open("wb") as f: f.write(b...
Check that a nice error message is raised when cache is corrupted.
test_corrupted_file_error_message
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_kddcup99.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_kddcup99.py
BSD-3-Clause
def mock_data_home(tmp_path_factory): """Test fixture run once and common to all tests of this module""" Image = pytest.importorskip("PIL.Image") data_dir = tmp_path_factory.mktemp("scikit_learn_lfw_test") lfw_home = data_dir / "lfw_home" lfw_home.mkdir(parents=True, exist_ok=True) random_stat...
Test fixture run once and common to all tests of this module
mock_data_home
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_lfw.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_lfw.py
BSD-3-Clause
def test_fetch_lfw_people_internal_cropping(mock_data_home): """Check that we properly crop the images. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/24942 """ # If cropping was not done properly and we don't resize the images, the images would # have their origin...
Check that we properly crop the images. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/24942
test_fetch_lfw_people_internal_cropping
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_lfw.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_lfw.py
BSD-3-Clause
def test_fetch_openml_as_frame_true( monkeypatch, data_id, dataset_params, n_samples, n_features, n_targets, parser, gzip_response, ): """Check the behaviour of `fetch_openml` with `as_frame=True`. Fetch by ID and/or name (depending if the file was previously cached). """ ...
Check the behaviour of `fetch_openml` with `as_frame=True`. Fetch by ID and/or name (depending if the file was previously cached).
test_fetch_openml_as_frame_true
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_as_frame_false( monkeypatch, data_id, dataset_params, n_samples, n_features, n_targets, parser, ): """Check the behaviour of `fetch_openml` with `as_frame=False`. Fetch both by ID and/or name + version. """ pytest.importorskip("pandas") _monkey_pat...
Check the behaviour of `fetch_openml` with `as_frame=False`. Fetch both by ID and/or name + version.
test_fetch_openml_as_frame_false
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_consistency_parser(monkeypatch, data_id): """Check the consistency of the LIAC-ARFF and pandas parsers.""" pd = pytest.importorskip("pandas") _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response=True) bunch_liac = fetch_openml( data_id=data_id, as_f...
Check the consistency of the LIAC-ARFF and pandas parsers.
test_fetch_openml_consistency_parser
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_equivalence_array_dataframe(monkeypatch, parser): """Check the equivalence of the dataset when using `as_frame=False` and `as_frame=True`. """ pytest.importorskip("pandas") data_id = 61 _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response=True) bunch_as...
Check the equivalence of the dataset when using `as_frame=False` and `as_frame=True`.
test_fetch_openml_equivalence_array_dataframe
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_iris_pandas(monkeypatch, parser): """Check fetching on a numerical only dataset with string labels.""" pd = pytest.importorskip("pandas") CategoricalDtype = pd.api.types.CategoricalDtype data_id = 61 data_shape = (150, 4) target_shape = (150,) frame_shape = (150, 5) ...
Check fetching on a numerical only dataset with string labels.
test_fetch_openml_iris_pandas
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_forcing_targets(monkeypatch, parser, target_column): """Check that we can force the target to not be the default target.""" pd = pytest.importorskip("pandas") data_id = 61 _monkey_patch_webbased_functions(monkeypatch, data_id, True) bunch_forcing_target = fetch_openml( ...
Check that we can force the target to not be the default target.
test_fetch_openml_forcing_targets
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_equivalence_frame_return_X_y(monkeypatch, data_id, parser): """Check the behaviour of `return_X_y=True` when `as_frame=True`.""" pd = pytest.importorskip("pandas") _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response=True) bunch = fetch_openml( data_id=data...
Check the behaviour of `return_X_y=True` when `as_frame=True`.
test_fetch_openml_equivalence_frame_return_X_y
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_equivalence_array_return_X_y(monkeypatch, data_id, parser): """Check the behaviour of `return_X_y=True` when `as_frame=False`.""" pytest.importorskip("pandas") _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response=True) bunch = fetch_openml( data_id=data_id,...
Check the behaviour of `return_X_y=True` when `as_frame=False`.
test_fetch_openml_equivalence_array_return_X_y
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_difference_parsers(monkeypatch): """Check the difference between liac-arff and pandas parser.""" pytest.importorskip("pandas") data_id = 1119 _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response=True) # When `as_frame=False`, the categories will be ordinally en...
Check the difference between liac-arff and pandas parser.
test_fetch_openml_difference_parsers
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def datasets_column_names(): """Returns the columns names for each dataset.""" return { 61: ["sepallength", "sepalwidth", "petallength", "petalwidth", "class"], 2: [ "family", "product-type", "steel", "carbon", "hardness", "...
Returns the columns names for each dataset.
datasets_column_names
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_types_inference( monkeypatch, data_id, parser, expected_n_categories, expected_n_floats, expected_n_ints, gzip_response, datasets_column_names, datasets_missing_values, ): """Check that `fetch_openml` infer the right number of categories, integers, and f...
Check that `fetch_openml` infer the right number of categories, integers, and floats.
test_fetch_openml_types_inference
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_requires_pandas_error(monkeypatch, params): """Check that we raise the proper errors when we require pandas.""" data_id = 1119 try: check_pandas_support("test_fetch_openml_requires_pandas") except ImportError: _monkey_patch_webbased_functions(monkeypatch, data_id, T...
Check that we raise the proper errors when we require pandas.
test_fetch_openml_requires_pandas_error
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_sparse_arff_error(monkeypatch, params, err_msg): """Check that we raise the expected error for sparse ARFF datasets and a wrong set of incompatible parameters. """ pytest.importorskip("pandas") data_id = 292 _monkey_patch_webbased_functions(monkeypatch, data_id, True) ...
Check that we raise the expected error for sparse ARFF datasets and a wrong set of incompatible parameters.
test_fetch_openml_sparse_arff_error
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_convert_arff_data_dataframe_warning_low_memory_pandas(monkeypatch): """Check that we raise a warning regarding the working memory when using LIAC-ARFF parser.""" pytest.importorskip("pandas") data_id = 1119 _monkey_patch_webbased_functions(monkeypatch, data_id, True) msg = "Could not ...
Check that we raise a warning regarding the working memory when using LIAC-ARFF parser.
test_convert_arff_data_dataframe_warning_low_memory_pandas
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_iris_warn_multiple_version(monkeypatch, gzip_response): """Check that a warning is raised when multiple versions exist and no version is requested.""" data_id = 61 data_name = "iris" _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response) msg = re.escape( ...
Check that a warning is raised when multiple versions exist and no version is requested.
test_fetch_openml_iris_warn_multiple_version
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_no_target(monkeypatch, gzip_response): """Check that we can get a dataset without target.""" data_id = 61 target_column = None expected_observations = 150 expected_features = 5 _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response) data = fetch_openml( ...
Check that we can get a dataset without target.
test_fetch_openml_no_target
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_missing_values_pandas(monkeypatch, gzip_response, parser): """check that missing values in categories are compatible with pandas categorical""" pytest.importorskip("pandas") data_id = 42585 _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response=gzip_response) penguins = f...
check that missing values in categories are compatible with pandas categorical
test_missing_values_pandas
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_inactive(monkeypatch, gzip_response, dataset_params): """Check that we raise a warning when the dataset is inactive.""" data_id = 40675 _monkey_patch_webbased_functions(monkeypatch, data_id, gzip_response) msg = "Version 1 of dataset glass2 is inactive," with pytest.warns(UserW...
Check that we raise a warning when the dataset is inactive.
test_fetch_openml_inactive
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_overwrite_default_params_read_csv(monkeypatch): """Check that we can overwrite the default parameters of `read_csv`.""" pytest.importorskip("pandas") data_id = 1590 _monkey_patch_webbased_functions(monkeypatch, data_id=data_id, gzip_response=False) common_params = { "d...
Check that we can overwrite the default parameters of `read_csv`.
test_fetch_openml_overwrite_default_params_read_csv
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_verify_checksum(monkeypatch, as_frame, tmpdir, parser): """Check that the checksum is working as expected.""" if as_frame or parser == "pandas": pytest.importorskip("pandas") data_id = 2 _monkey_patch_webbased_functions(monkeypatch, data_id, True) # create a temporary...
Check that the checksum is working as expected.
test_fetch_openml_verify_checksum
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_with_ignored_feature(monkeypatch, gzip_response, parser): """Check that we can load the "zoo" dataset. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/14340 """ if parser == "pandas": pytest.importorskip("pandas") data_id = 62 _monke...
Check that we can load the "zoo" dataset. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/14340
test_fetch_openml_with_ignored_feature
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_leading_whitespace(monkeypatch): """Check that we can strip leading whitespace in pandas parser. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/25311 """ pd = pytest.importorskip("pandas") data_id = 1590 _monkey_patch_webbased_functions(mo...
Check that we can strip leading whitespace in pandas parser. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/25311
test_fetch_openml_leading_whitespace
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_fetch_openml_quotechar_escapechar(monkeypatch): """Check that we can handle escapechar and single/double quotechar. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/25478 """ pd = pytest.importorskip("pandas") data_id = 42074 _monkey_patch_webbased_funct...
Check that we can handle escapechar and single/double quotechar. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/25478
test_fetch_openml_quotechar_escapechar
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_openml.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_openml.py
BSD-3-Clause
def test_make_classification_informative_features(): """Test the construction of informative features in make_classification Also tests `n_clusters_per_class`, `n_classes`, `hypercube` and fully-specified `weights`. """ # Create very separate clusters; check that vertices are unique and # corre...
Test the construction of informative features in make_classification Also tests `n_clusters_per_class`, `n_classes`, `hypercube` and fully-specified `weights`.
test_make_classification_informative_features
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_samples_generator.py
BSD-3-Clause
def test_make_classification_return_x_y(): """ Test that make_classification returns a Bunch when return_X_y is False. Also that bunch.X is the same as X """ kwargs = { "n_samples": 100, "n_features": 20, "n_informative": 5, "n_redundant": 1, "n_repeated": 1...
Test that make_classification returns a Bunch when return_X_y is False. Also that bunch.X is the same as X
test_make_classification_return_x_y
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_samples_generator.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_samples_generator.py
BSD-3-Clause
def _load_svmlight_local_test_file(filename, **kwargs): """ Helper to load resource `filename` with `importlib.resources` """ data_path = _svmlight_local_test_file_path(filename) with data_path.open("rb") as f: return load_svmlight_file(f, **kwargs)
Helper to load resource `filename` with `importlib.resources`
_load_svmlight_local_test_file
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_svmlight_format.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_svmlight_format.py
BSD-3-Clause
def test_load_large_qid(): """ load large libsvm / svmlight file with qid attribute. Tests 64-bit query ID """ data = b"\n".join( ( "3 qid:{0} 1:0.53 2:0.12\n2 qid:{0} 1:0.13 2:0.1".format(i).encode() for i in range(1, 40 * 1000 * 1000) ) ) X, y, qid = loa...
load large libsvm / svmlight file with qid attribute. Tests 64-bit query ID
test_load_large_qid
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_svmlight_format.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_svmlight_format.py
BSD-3-Clause
def test_multilabel_y_explicit_zeros(tmp_path, csr_container): """ Ensure that if y contains explicit zeros (i.e. elements of y.data equal to 0) then those explicit zeros are not encoded. """ save_path = str(tmp_path / "svm_explicit_zero") rng = np.random.RandomState(42) X = rng.randn(3, 5)....
Ensure that if y contains explicit zeros (i.e. elements of y.data equal to 0) then those explicit zeros are not encoded.
test_multilabel_y_explicit_zeros
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_svmlight_format.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_svmlight_format.py
BSD-3-Clause
def test_dump_read_only(tmp_path): """Ensure that there is no ValueError when dumping a read-only `X`. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/28026 """ rng = np.random.RandomState(42) X = rng.randn(5, 2) y = rng.randn(5) # Convert to memmap-backed ...
Ensure that there is no ValueError when dumping a read-only `X`. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/28026
test_dump_read_only
python
scikit-learn/scikit-learn
sklearn/datasets/tests/test_svmlight_format.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/tests/test_svmlight_format.py
BSD-3-Clause
def get_covariance(self): """Compute data covariance with the generative model. ``cov = components_.T * S**2 * components_ + sigma2 * eye(n_features)`` where S**2 contains the explained variances, and sigma2 contains the noise variances. Returns ------- cov : ar...
Compute data covariance with the generative model. ``cov = components_.T * S**2 * components_ + sigma2 * eye(n_features)`` where S**2 contains the explained variances, and sigma2 contains the noise variances. Returns ------- cov : array of shape=(n_features, n_features)...
get_covariance
python
scikit-learn/scikit-learn
sklearn/decomposition/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/_base.py
BSD-3-Clause
def get_precision(self): """Compute data precision matrix with the generative model. Equals the inverse of the covariance but computed with the matrix inversion lemma for efficiency. Returns ------- precision : array, shape=(n_features, n_features) Estimated...
Compute data precision matrix with the generative model. Equals the inverse of the covariance but computed with the matrix inversion lemma for efficiency. Returns ------- precision : array, shape=(n_features, n_features) Estimated precision of data.
get_precision
python
scikit-learn/scikit-learn
sklearn/decomposition/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/_base.py
BSD-3-Clause
def fit(self, X, y=None): """Placeholder for fit. Subclasses should implement this method! Fit the model with X. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data, where `n_samples` is the number of samples and `n_featur...
Placeholder for fit. Subclasses should implement this method! Fit the model with X. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data, where `n_samples` is the number of samples and `n_features` is the number of features. ...
fit
python
scikit-learn/scikit-learn
sklearn/decomposition/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/_base.py
BSD-3-Clause