3 Synthetic Data
| (require datasets/synthetic) | package: datasets-core |
Each generator mirrors the scikit-learn 1.8 function of the same name and returns a dataset table. Features are named "x0", "x1", …, and hold flonums. The target is "y"; a regression with several targets has "y0", "y1", …, and the two manifolds have "t". Class labels are exact integers.
Keywords follow scikit-learn’s parameters: underscores become hyphens, boolean parameters gain a ?, and random_state becomes #:seed.
Procedure |
| scikit-learn |
| Differences |
| make_blobs |
| #:n-features defaults to #f; centres in metadata, not return_centers | |
| make_moons |
| none | |
| make_circles |
| none | |
| make_classification |
| feature roles in column descriptions, not return_X_y | |
| make_regression |
| coefficients in metadata, not coef | |
| make_friedman1 |
| none | |
| make_friedman2 |
| none | |
| make_friedman3 |
| none | |
| make_hastie_10_2 |
| labels are exact -1 and 1 | |
| make_swiss_roll |
| none | |
| make_s_curve |
| none | |
| make_gaussian_quantiles |
| #:n-features defaults to #f |
Arguments scikit-learn accepts but ignores, such as an #:n-features that disagrees with the given centres, are contract violations here. Numbers must be finite as flonums: an exact argument such as (expt 10 400), whose real->double-flonum is infinite, is a contract violation. A bound on an argument must hold for both the value and its flonum, so an exact #:factor just below 1 that rounds to 1.0, or a positive #:class-sep that underflows to 0.0, is also a violation.
3.1 Seeds and reproducibility
#:seed takes one of four forms:
#f: a fresh seed in [0, 231) is drawn from crypto-random-bytes and recorded in the metadata.
an integer k: a new generator in the state (random-seed k) produces.
a state vector, as from pseudo-random-generator->vector: a new generator in that state.
a pseudo-random generator: used and advanced in place.
current-pseudo-random-generator is never read or advanced. Each generator draws in the order of scikit-learn 1.8’s NumPy calls, including draws whose values are then multiplied by zero. On one platform, the same arguments and seed give equal? tables. Across platforms, labels and uniform-only columns are bit-identical; values passed through log, exp, sin, cos or atan agree to a relative 10-12. The stream is not NumPy’s: a seed does not reproduce scikit-learn’s values.
The source metadata’s arguments hash records every keyword with the seed that reproduces the table, so passing it back replays the table.
> (define a (make-moons #:n-samples 4 #:noise 0.1 #:seed 7)) > (equal? a (make-moons #:n-samples 4 #:noise 0.1 #:seed 7)) #t
> (hash-ref (hash-ref (dataset-table-info a) "source") "arguments") '#hash(("n-samples" . 4) ("noise" . 0.1) ("seed" . 7) ("shuffle?" . #t))
3.2 Metadata
Columns are the features, then the targets. Features have type real and original name X[:, j]. Class labels have type integer; other targets have type real and original name y, y[:, k] or t. Every column has no levels, no unit and no missing values. Descriptions of make-classification features are scikit-learn’s feature_info roles: informative, redundant, repeated or random; make-regression features are informative when their coefficient is nonzero and random otherwise.
The info hash is deeply immutable and has exactly these keys:
Key |
| Value |
name |
| the generator’s name, such as "make-blobs" |
rows, column-count, columns |
| as for registry datasets |
identifiers |
| '() |
suggested-targets |
| every target column, in order |
source-url |
| the scikit-learn 1.8 page for the function |
source-version |
| "scikit-learn 1.8.0 semantics; stream 1, not NumPy-compatible" |
source-sha256, sha256, license, time-series |
| #f |
citation |
| the reference scikit-learn cites for the generator |
notes |
| one sentence |
source |
| the hash below |
The source hash has generator (the name), reference (such as "sklearn.datasets.make_blobs"), reference-version ("1.8.0"), stream (1), arguments and derived. arguments maps each keyword name, without #:, to its value as given or defaulted; the seed entry is the integer that reproduces the table, or for a generator or vector its state before the first draw. derived holds centers for make-blobs and coef for make-regression, and is empty otherwise. Generated tables are not registry entries.
3.3 Generators
procedure
(make-blobs [ #:n-samples n-samples #:n-features n-features #:centers centers #:cluster-std cluster-std #:center-box center-box #:shuffle? shuffle? #:seed seed]) → dataset-table?
n-samples :
(or/c exact-positive-integer? (and/c (non-empty-listof exact-nonnegative-integer?) (λ (ns) (positive? (apply + ns))))) = 100 n-features : (or/c #f exact-positive-integer?) = #f
centers :
(or/c #f exact-positive-integer? (non-empty-listof (non-empty-listof rational?))) = #f
cluster-std :
(or/c (and/c rational? (>=/c 0)) (non-empty-listof (and/c rational? (>=/c 0)))) = 1.0 center-box : (list/c rational? rational?) = '(-10.0 10.0) shuffle? : boolean? = #t
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
> (define b (make-blobs #:n-samples 6 #:centers 2 #:seed 0)) > (dataset-table-names b) '("x0" "x1" "y")
> (hash-ref (hash-ref (hash-ref (dataset-table-info b) "source") "derived") "centers") '((7.143136981356072 3.188431217147434) (-5.88690358318294 -1.862973400274866))
procedure
(make-moons [ #:n-samples n-samples #:shuffle? shuffle? #:noise noise #:seed seed]) → dataset-table?
n-samples :
(or/c exact-positive-integer? (list/c exact-nonnegative-integer? exact-nonnegative-integer?)) = 100 shuffle? : boolean? = #t noise : (or/c #f (and/c rational? (>=/c 0))) = #f
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
> (dataset-table-column (make-moons #:n-samples 5 #:shuffle? #f) "y") '#(0 0 1 1 1)
procedure
(make-circles [ #:n-samples n-samples #:shuffle? shuffle? #:noise noise #:factor factor #:seed seed]) → dataset-table?
n-samples :
(or/c exact-nonnegative-integer? (list/c exact-nonnegative-integer? exact-nonnegative-integer?)) = 100 shuffle? : boolean? = #t noise : (or/c #f (and/c rational? (>=/c 0))) = #f factor : (and/c rational? (>=/c 0) (</c 1)) = 0.8
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
procedure
(make-classification [ #:n-samples n-samples #:n-features n-features #:n-informative n-informative #:n-redundant n-redundant #:n-repeated n-repeated #:n-classes n-classes #:n-clusters-per-class n-clusters-per-class #:weights weights #:flip-y flip-y #:class-sep class-sep #:hypercube? hypercube? #:shift shift #:scale scale #:shuffle? shuffle? #:seed seed]) → dataset-table? n-samples : exact-positive-integer? = 100 n-features : exact-positive-integer? = 20 n-informative : exact-positive-integer? = 2 n-redundant : exact-nonnegative-integer? = 2 n-repeated : exact-nonnegative-integer? = 0 n-classes : exact-positive-integer? = 2 n-clusters-per-class : exact-positive-integer? = 2
weights : (or/c #f (listof (and/c rational? (real-in 0 1)))) = #f flip-y : (and/c rational? (real-in 0 1)) = 0.01 class-sep : (and/c rational? (>/c 0)) = 1.0 hypercube? : boolean? = #t shift : (or/c #f rational? (non-empty-listof rational?)) = 0.0
scale :
(or/c #f (and/c rational? (>/c 0)) (non-empty-listof (and/c rational? (>/c 0)))) = 1.0 shuffle? : boolean? = #t
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
> (for/list ([c (hash-ref (dataset-table-info (make-classification #:n-features 5 #:seed 0)) "columns")]) (hash-ref c "description")) '("informative" "random" "redundant" "redundant" "informative" "class label")
procedure
(make-regression [ #:n-samples n-samples #:n-features n-features #:n-informative n-informative #:n-targets n-targets #:bias bias #:effective-rank effective-rank #:tail-strength tail-strength #:noise noise #:shuffle? shuffle? #:seed seed]) → dataset-table? n-samples : exact-positive-integer? = 100 n-features : exact-positive-integer? = 100 n-informative : exact-nonnegative-integer? = 10 n-targets : exact-positive-integer? = 1 bias : rational? = 0.0 effective-rank : (or/c #f exact-positive-integer?) = #f tail-strength : (and/c rational? (real-in 0 1)) = 0.5 noise : (and/c rational? (>=/c 0)) = 0.0 shuffle? : boolean? = #t
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
> (hash-ref (hash-ref (hash-ref (dataset-table-info (make-regression #:n-samples 3 #:n-features 3 #:n-informative 1 #:seed 0)) "source") "derived") "coef") '((0.0) (50.29567011201274) (0.0))
procedure
(make-friedman1 [ #:n-samples n-samples #:n-features n-features #:noise noise #:seed seed]) → dataset-table? n-samples : exact-positive-integer? = 100 n-features : (integer-in 5 #f) = 10 noise : (and/c rational? (>=/c 0)) = 0.0
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
procedure
(make-friedman2 [ #:n-samples n-samples #:noise noise #:seed seed]) → dataset-table? n-samples : exact-positive-integer? = 100 noise : (and/c rational? (>=/c 0)) = 0.0
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
procedure
(make-friedman3 [ #:n-samples n-samples #:noise noise #:seed seed]) → dataset-table? n-samples : exact-positive-integer? = 100 noise : (and/c rational? (>=/c 0)) = 0.0
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
procedure
(make-hastie-10-2 [ #:n-samples n-samples #:seed seed]) → dataset-table? n-samples : exact-positive-integer? = 12000
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
procedure
(make-swiss-roll [ #:n-samples n-samples #:noise noise #:hole? hole? #:seed seed]) → dataset-table? n-samples : exact-positive-integer? = 100 noise : (and/c rational? (>=/c 0)) = 0.0 hole? : boolean? = #f
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
procedure
(make-s-curve [ #:n-samples n-samples #:noise noise #:seed seed]) → dataset-table? n-samples : exact-positive-integer? = 100 noise : (and/c rational? (>=/c 0)) = 0.0
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
procedure
(make-gaussian-quantiles [ #:mean mean #:cov cov #:n-samples n-samples #:n-features n-features #:n-classes n-classes #:shuffle? shuffle? #:seed seed]) → dataset-table? mean : (or/c #f (non-empty-listof rational?)) = #f cov : (and/c rational? (>=/c 0)) = 1.0 n-samples : exact-positive-integer? = 100 n-features : (or/c #f exact-positive-integer?) = #f n-classes : exact-positive-integer? = 3 shuffle? : boolean? = #t
seed :
(or/c #f (integer-in 0 (sub1 (expt 2 31))) pseudo-random-generator? pseudo-random-generator-vector?) = #f
> (dataset-table-column (make-gaussian-quantiles #:n-samples 7 #:n-classes 3 #:shuffle? #f #:seed 0) "y") '#(0 0 1 1 2 2 2)