deepbox/datasets
Synthetic Generators
Generators for classification, regression, clustering, manifold and low-rank test data, modeled on scikit-learn's make_* functions.
- Synthetic data
Overview
- Generators take an options object (
nSamples,nFeatures,noise,randomStateand others) and return a tuple[X, y]of tensors. Features and regression targets arefloat64, and class labels areint32. - Pass
randomStatefor a repeatable dataset. Without it the generators use the global stream, sosetSeedalso works. - Since 1.5.0,
makeFriedman2,makeFriedman3,makeSparseUncorrelatedandmakeLowRankMatrixfollow scikit-learn's definitions, so their output differs from 1.0.0.
makeBiclusters
function makeBiclusters(options?: { shape?: [ number, number ]; nClusters?: number; noise?: number; randomState?: number; }): [ Tensor, Tensor, Tensor ];Generate a bicluster dataset.
Every row and every column is assigned independently and uniformly to one of nClusters clusters (so for small shapes a cluster can end up empty). Entry (i, j) is 1 when row i and column j share a cluster and 0 otherwise, plus Gaussian noise.
Parameters
optionsoptional{ shape?: [ number, number ]; nClusters?: number; noise?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor, Tensor ]A tuple [X, rows, cols] where rows (length nRows) and cols (length nCols) are int32 cluster labels.
Throws
makeBlobs
function makeBlobs(options?: { nSamples?: number; nFeatures?: number; centers?: number | number[][]; clusterStd?: number | readonly number[]; randomState?: number; shuffle?: boolean; }): [ Tensor, Tensor ];Generate isotropic Gaussian blobs for clustering.
Samples are drawn from Gaussian distributions centered at randomly generated or user-specified locations. Useful for testing clustering algorithms.
Parameters
optionsoptional{ nSamples?: number; nFeatures?: number; centers?: number | number[][]; clusterStd?: number | readonly number[]; randomState?: number; shuffle?: boolean; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y] where X has shape [nSamples, nFeatures] and y has shape [nSamples] with dtype int32. The first nSamples % nCenters clusters get one extra sample.
Throws
makeCheckerboard
function makeCheckerboard(options?: { shape?: [ number, number ]; nClusters?: [ number, number ]; noise?: number; randomState?: number; }): [ Tensor, Tensor, Tensor ];Generate a checkerboard dataset.
Rows and columns are split into contiguous, near-equal blocks. Entry (i, j) is 1 when the parity of its row block index plus its column block index is even and 0 otherwise, plus Gaussian noise.
Parameters
optionsoptional{ shape?: [ number, number ]; nClusters?: [ number, number ]; noise?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor, Tensor ]A tuple [X, rows, cols] where rows (length nRows) and cols (length nCols) are int32 block labels.
Throws
makeCircles
function makeCircles(options?: { nSamples?: number; noise?: number; factor?: number; randomState?: number; shuffle?: boolean; }): [ Tensor, Tensor ];Generate a large circle containing a smaller circle in 2D.
Useful for testing algorithms that handle non-linearly separable data.
Parameters
optionsoptional{ nSamples?: number; noise?: number; factor?: number; randomState?: number; shuffle?: boolean; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y] where X has shape [nSamples, 2] and y has shape [nSamples] with dtype int32.
makeClassification
function makeClassification(options?: { nSamples?: number; nFeatures?: number; nInformative?: number; nRedundant?: number; nClasses?: number; flipY?: number; randomState?: number; }): [ Tensor, Tensor ];Generate a random n-class classification dataset.
Produces informative features drawn from class-conditional Gaussians, redundant features as random linear combinations of the informative ones, and noise features sampled from N(0, 1).
Parameters
optionsoptional{ nSamples?: number; nFeatures?: number; nInformative?: number; nRedundant?: number; nClasses?: number; flipY?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y] where X has shape [nSamples, nFeatures] and y has shape [nSamples] with dtype int32.
Throws
makeFriedman1
function makeFriedman1(options?: { nSamples?: number; nFeatures?: number; noise?: number; randomState?: number; }): [ Tensor, Tensor ];Generate the Friedman #1 regression dataset.
y = 10 * sin(pi * x0 * x1) + 20 * (x2 - 0.5)^2 + 10 * x3 + 5 * x4 + noise
Features are uniform on [0, 1); only the first five influence the target.
Parameters
optionsoptional{ nSamples?: number; nFeatures?: number; noise?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y].
makeFriedman2
function makeFriedman2(options?: { nSamples?: number; noise?: number; randomState?: number; }): [ Tensor, Tensor ];Generate the Friedman #2 regression dataset.
y = sqrt(x0^2 + (x1 * x2 - 1/(x1 * x3))^2) + noise
Features: x0 ~ U[0, 100), x1 ~ U[40 pi, 560 pi), x2 ~ U[0, 1), x3 ~ U[1, 11).
Parameters
optionsoptional{ nSamples?: number; noise?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y].
makeFriedman3
function makeFriedman3(options?: { nSamples?: number; noise?: number; randomState?: number; }): [ Tensor, Tensor ];Generate the Friedman #3 regression dataset.
y = atan((x1 * x2 - 1/(x1 * x3)) / x0) + noise
Features: x0 ~ U[0, 100), x1 ~ U[40 pi, 560 pi), x2 ~ U[0, 1), x3 ~ U[1, 11).
Parameters
optionsoptional{ nSamples?: number; noise?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y].
makeGaussianQuantiles
function makeGaussianQuantiles(options?: { nSamples?: number; nFeatures?: number; nClasses?: number; randomState?: number; }): [ Tensor, Tensor ];Generate a dataset with classes separated by concentric Gaussian quantile shells.
Samples are drawn from an isotropic Gaussian and ranked by their Euclidean distance from the origin. Class c receives the samples in rank block c, so class sizes differ by at most one (the last class takes the remainder, as in scikit-learn). Samples are returned in draw order, not sorted by class.
Parameters
optionsoptional{ nSamples?: number; nFeatures?: number; nClasses?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y] where X has shape [nSamples, nFeatures] and y has shape [nSamples] with dtype int32.
makeLowRankMatrix
function makeLowRankMatrix(options?: { nSamples?: number; nFeatures?: number; effectiveRank?: number; tailStrength?: number; randomState?: number; }): Tensor;Generate a mostly low-rank matrix with a bell-shaped singular value profile.
Details
The matrix is U diag(s) V^T where U and V have random orthonormal columns, so its singular values are exactly s_i = (1 - tailStrength) * exp(-(i / effectiveRank)^2) + tailStrength * exp(-0.1 * i / effectiveRank) for i = 0 .. min(nSamples, nFeatures) - 1 (the model used by scikit-learn's make_low_rank_matrix). Most of the spectrum is concentrated in the first effectiveRank values; the tail decays slowly.
Parameters
optionsoptional{ nSamples?: number; nFeatures?: number; effectiveRank?: number; tailStrength?: number; randomState?: number; }- Configuration options.
Returns
TensorA 2D Tensor of shape [nSamples, nFeatures].
Throws
makeMoons
function makeMoons(options?: { nSamples?: number; noise?: number; randomState?: number; shuffle?: boolean; }): [ Tensor, Tensor ];Generate two interleaving half-circle (moons) dataset.
Class 0 is the upper half of the unit circle, class 1 the lower half of a unit circle shifted by (1, 0.5). Both arcs include their endpoints, as in scikit-learn. Useful for testing algorithms that handle non-linearly separable data.
Parameters
optionsoptional{ nSamples?: number; noise?: number; randomState?: number; shuffle?: boolean; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y] where X has shape [nSamples, 2] and y has shape [nSamples] with dtype int32.
makeRegression
function makeRegression(options?: { nSamples?: number; nFeatures?: number; nInformative?: number; bias?: number; noise?: number; randomState?: number; }): [ Tensor, Tensor ];Generate a random regression dataset.
Features are drawn from N(0, 1) and the target is a linear combination of the first nInformative features (coefficients drawn from N(0, 1)) plus an optional bias and Gaussian noise.
Parameters
optionsoptional{ nSamples?: number; nFeatures?: number; nInformative?: number; bias?: number; noise?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y] where X has shape [nSamples, nFeatures] and y has shape [nSamples].
Throws
makeSCurve
function makeSCurve(options?: { nSamples?: number; noise?: number; randomState?: number; }): [ Tensor, Tensor ];Generate an S-curve dataset (3D manifold).
Useful for testing manifold learning algorithms.
Parameters
optionsoptional{ nSamples?: number; noise?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, t] where X is 3D coordinates and t is the manifold position.
makeSPDMatrix
function makeSPDMatrix(options?: { nDim?: number; randomState?: number; }): Tensor;Generate a random symmetric positive-definite matrix.
The matrix is Q diag(lambda) Q^T with Q a random orthogonal matrix and eigenvalues lambda_i uniform on [1, 2), so it is exactly symmetric, positive definite and well conditioned (condition number below 2), as in scikit-learn's make_spd_matrix.
Parameters
optionsoptional{ nDim?: number; randomState?: number; }- Configuration options.
Returns
TensorA 2D Tensor of shape [nDim, nDim].
makeSparseUncorrelated
function makeSparseUncorrelated(options?: { nSamples?: number; nFeatures?: number; randomState?: number; }): [ Tensor, Tensor ];Generate a sparse uncorrelated regression dataset.
Features are drawn from N(0, 1). Only the first four influence the target: y ~ N(x0 + 2*x1 - 2*x2 - 1.5*x3, 1), the same model as scikit-learn's make_sparse_uncorrelated. The remaining features are pure noise.
Parameters
optionsoptional{ nSamples?: number; nFeatures?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, y].
Throws
makeSwissRoll
function makeSwissRoll(options?: { nSamples?: number; noise?: number; randomState?: number; }): [ Tensor, Tensor ];Generate a Swiss Roll dataset (3D manifold).
Useful for testing manifold learning and dimensionality reduction algorithms.
Parameters
optionsoptional{ nSamples?: number; noise?: number; randomState?: number; }- Configuration options.
Returns
[ Tensor, Tensor ]A tuple [X, t] where X is 3D coordinates and t is the manifold position.
import { makeBlobs, makeClassification, makeMoons, makeRegression, makeSwissRoll,} from "deepbox/datasets"; const [X, y] = makeClassification({ nSamples: 100, nFeatures: 4, randomState: 0 });console.log(X.shape, y.shape, y.dtype); const [Xr, yr] = makeRegression({ nSamples: 100, nFeatures: 4, noise: 0.1, randomState: 0 });console.log(Xr.shape, yr.shape); const [blobs, blobLabels] = makeBlobs({ nSamples: 90, centers: 3, randomState: 0 });console.log(blobs.shape, blobLabels.shape); console.log(makeMoons({ nSamples: 100, noise: 0.1, randomState: 0 })[0].shape);console.log(makeSwissRoll({ nSamples: 100, randomState: 0 })[0].shape);Found a mistake? Open an issue.