MCPcopy Create free account
hub / github.com/PythonOT/POT / make_data_classif

Function make_data_classif

ot/datasets.py:86–176  ·  view source on GitHub ↗

Dataset generation for classification problems Parameters ---------- dataset : str type of classification problem (see code) n : int number of training samples nz : float noise level (>0) p : float proportion of one class in the binary setting

(dataset, n, nz=0.5, theta=0, p=0.5, random_state=None, **kwargs)

Source from the content-addressed store, hash-verified

84
85
86def make_data_classif(dataset, n, nz=0.5, theta=0, p=0.5, random_state=None, **kwargs):
87 """Dataset generation for classification problems
88
89 Parameters
90 ----------
91 dataset : str
92 type of classification problem (see code)
93 n : int
94 number of training samples
95 nz : float
96 noise level (>0)
97 p : float
98 proportion of one class in the binary setting
99 random_state : int, RandomState instance or None, optional (default=None)
100 If int, random_state is the seed used by the random number generator;
101 If RandomState instance, random_state is the random number generator;
102 If None, the random number generator is the RandomState instance used
103 by `np.random`.
104
105 Returns
106 -------
107 X : ndarray, shape (n, d)
108 `n` observation of size `d`
109 y : ndarray, shape (n,)
110 labels of the samples.
111 """
112 generator = check_random_state(random_state)
113
114 if dataset.lower() == "3gauss":
115 y = np.floor((np.arange(n) * 1.0 / n * 3)) + 1
116 x = np.zeros((n, 2))
117 # class 1
118 x[y == 1, 0] = -1.0
119 x[y == 1, 1] = -1.0
120 x[y == 2, 0] = -1.0
121 x[y == 2, 1] = 1.0
122 x[y == 3, 0] = 1.0
123 x[y == 3, 1] = 0
124
125 x[y != 3, :] += 1.5 * nz * generator.randn(sum(y != 3), 2)
126 x[y == 3, :] += 2 * nz * generator.randn(sum(y == 3), 2)
127
128 elif dataset.lower() == "3gauss2":
129 y = np.floor((np.arange(n) * 1.0 / n * 3)) + 1
130 x = np.zeros((n, 2))
131 y[y == 4] = 3
132 # class 1
133 x[y == 1, 0] = -2.0
134 x[y == 1, 1] = -2.0
135 x[y == 2, 0] = -2.0
136 x[y == 2, 1] = 2.0
137 x[y == 3, 0] = 2.0
138 x[y == 3, 1] = 0
139
140 x[y != 3, :] += nz * generator.randn(sum(y != 3), 2)
141 x[y == 3, :] += 2 * nz * generator.randn(sum(y == 3), 2)
142
143 elif dataset.lower() == "gaussrot":

Calls 10

check_random_stateFunction · 0.85
make_2D_samples_gaussFunction · 0.85
floorMethod · 0.45
arangeMethod · 0.45
zerosMethod · 0.45
randnMethod · 0.45
sumMethod · 0.45
dotMethod · 0.45
concatenateMethod · 0.45
onesMethod · 0.45