make_classification#
- cuml.datasets.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, order='F', dtype='float32', _centroids=None, _informative_covariance=None, _redundant_covariance=None, _repeated_indices=None)[source]#
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 length2*class_sepand assigns an equal number of clusters to each class. It introduces interdependence between these features and adds various types of further noise to the data. Without shuffling,Xhorizontally stacks features in the following order: the primaryn_informativefeatures, followed byn_redundantlinear combinations of the informative features, followed byn_repeatedduplicates, drawn randomly with replacement from the informative and redundant features. The remaining features are filled with random noise. Thus, without shuffling, all useful features are contained in the columnsX[:, :n_informative + n_redundant + n_repeated].- Parameters:
- n_samplesint, optional (default=100)
The number of samples.
- n_featuresint, optional (default=20)
The total number of features. These comprise
n_informativeinformative features,n_redundantredundant features,n_repeatedduplicated features andn_features-n_informative-n_redundant-n_repeateduseless features drawn at random.- n_informativeint, optional (default=2)
The number of informative features. Each class is composed of a number of gaussian clusters each located around the vertices of a hypercube in a subspace of dimension
n_informative. For each cluster, informative features are drawn independently from N(0, 1) and then randomly linearly combined within each cluster in order to add covariance. The clusters are then placed on the vertices of the hypercube.- n_redundantint, optional (default=2)
The number of redundant features. These features are generated as random linear combinations of the informative features.
- n_repeatedint, optional (default=0)
The number of duplicated features, drawn randomly from the informative and the redundant features.
- n_classesint, optional (default=2)
The number of classes (or labels) of the classification problem.
- n_clusters_per_classint, optional (default=2)
The number of clusters per class.
- weightsarray-like of shape (n_classes,) or (n_classes - 1,), (default=None)
The proportions of samples assigned to each class. If None, then classes are balanced. Note that if
len(weights) == n_classes - 1, then the last class weight is automatically inferred. More thann_samplessamples may be returned if the sum ofweightsexceeds 1.- flip_yfloat, optional (default=0.01)
The fraction of samples whose class is assigned randomly. Larger values introduce noise in the labels and make the classification task harder.
- class_sepfloat, optional (default=1.0)
The factor multiplying the hypercube size. Larger values spread out the clusters/classes and make the classification task easier.
- hypercubeboolean, optional (default=True)
If True, the clusters are put on the vertices of a hypercube. If False, the clusters are put on the vertices of a random polytope.
- shiftfloat, array of shape [n_features] or None, optional (default=0.0)
Shift features by the specified value. If None, then features are shifted by a random value drawn in [-class_sep, class_sep].
- scalefloat, array of shape [n_features] or None, optional (default=1.0)
Multiply features by the specified value. If None, then features are scaled by a random value drawn in [1, 100]. Note that scaling happens after shifting.
- shuffleboolean, optional (default=True)
Shuffle the samples and the features.
- random_stateint, RandomState instance or None (default)
Determines random number generation for dataset creation. Pass an int for reproducible output across multiple function calls. See Glossary.
- order: str, optional (default=’F’)
The order of the generated samples
- dtypestr, optional (default=’float32’)
Dtype of the generated samples
- _centroids: array of centroids of shape (n_clusters, n_informative)
- _informative_covariance: array for covariance between informative features
of shape (n_clusters, n_informative, n_informative)
- _redundant_covariance: array for covariance between redundant features
of shape (n_informative, n_redundant)
- _repeated_indices: array of indices for the repeated features
of shape (n_repeated, )
- Returns:
- Xdevice array of shape [n_samples, n_features]
The generated samples.
- ydevice array of shape [n_samples]
The integer labels for class membership of each sample.
Notes
The algorithm is adapted from Guyon [1] and was designed to generate the “Madelon” dataset. How we optimized for GPUs:
Firstly, we generate X from a standard univariate instead of zeros. This saves memory as we don’t need to generate univariates each time for each feature class (informative, repeated, etc.) while also providing the added speedup of generating a big matrix on GPU
We generate
order=Fconstruction. We exploit the fact that X is a generated from a univariate normal, and covariance is introduced with matrix multiplications. Which means, we can generate X as a 1D array and just reshape it to the desired order, which only updates the metadata and eliminates copiesLastly, we also shuffle by construction. Centroid indices are permuted for each sample, and then we construct the data for each centroid. This shuffle works for both
order=Candorder=Fand eliminates any need for secondary copies
References
[1]I. Guyon, “Design of experiments for the NIPS 2003 variable selection benchmark”, 2003.
Examples
>>> from cuml.datasets.classification import make_classification >>> X, y = make_classification(n_samples=10, n_features=4, ... n_informative=2, n_classes=2, ... random_state=10) >>> print(X) [[-1.7974224 0.24425316 0.39062843 -0.38293394] [ 0.6358963 1.4161923 0.06970507 -0.16085647] [-0.22802866 -1.1827322 0.3525861 0.276615 ] [ 1.7308872 0.43080002 0.05048406 0.29837844] [-1.9465544 0.5704457 -0.8997551 -0.27898186] [ 1.0575483 -0.9171263 0.09529338 0.01173469] [ 0.7917619 -1.0638094 -0.17599393 -0.06420116] [-0.6686142 -0.13951421 -0.6074711 0.21645583] [-0.88968956 -0.914443 0.1302423 0.02924336] [-0.8817671 -0.84549576 0.1845096 0.02556021]] >>> print(y) [1 0 1 1 1 1 1 1 1 0]