Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn RandomSampling

From Leeroopedia
Revision as of 16:37, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Scikit_learn_Scikit_learn_RandomSampling.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Machine Learning, Random Sampling
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for providing random sampling utilities including sampling without replacement and sparse random matrix generation, provided by scikit-learn.

Description

The sklearn.utils.random module provides utilities for random sampling. It re-exports sample_without_replacement from the Cython-optimized _random module and implements _random_choice_csc, which generates sparse random matrices given column class distributions. The sparse matrix generation is useful for creating random multi-label classification targets.

Usage

Use these utilities when you need efficient random sampling without replacement or need to generate sparse random matrices with specific class distributions, particularly in the context of multi-label classification data generation.

Code Reference

Source Location

Signature

def _random_choice_csc(n_samples, classes, class_probability=None, random_state=None):

# Re-exported from sklearn.utils._random:
sample_without_replacement

Import

from sklearn.utils.random import sample_without_replacement

I/O Contract

Inputs

Name Type Required Description
n_samples int Yes Number of samples to draw in each column
classes list of arrays Yes List of classes for each column (output)
class_probability list of arrays or None No Class distribution for each column (default None uses uniform)
random_state int, RandomState or None No Controls randomness of sampled classes (default None)

Outputs

Name Type Description
random_matrix sparse csc matrix of shape (n_samples, n_outputs) Sparse random matrix with sampled class labels

Usage Examples

Basic Usage

from sklearn.utils.random import sample_without_replacement
import numpy as np

# Sample 5 unique indices from a population of 100
indices = sample_without_replacement(100, 5, random_state=42)
print(indices)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment