@datagrok/eda 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,10 @@ const TRESHOLD = 0.5;
6
6
  const SHIFT = 1;
7
7
  const LIMIT = 2;
8
8
 
9
+ const MAX_INT = 10;
10
+ const MAX_FLOAT = 10;
11
+ const CATEGORIES = ['Alpha', 'Beta', 'Gamma', 'Delta'];
12
+
9
13
  /** Check lengths of columns */
10
14
  function checkLen(target: DG.Column, prediction: DG.Column): void {
11
15
  if (target.length !== prediction.length)
@@ -119,3 +123,74 @@ export function accuracy(target: DG.Column, prediction: DG.Column): number {
119
123
 
120
124
  return correctPredictions / rows;
121
125
  }
126
+
127
+ /** Return dataframe with missing values */
128
+ export function dataWithMissingVals(rows: number, intCols: number, floatCols: number,
129
+ strCols: number, misValCount: number): {df: DG.DataFrame, misValsIds: Map<string, number[]>} {
130
+ const catsCount = CATEGORIES.length;
131
+ const cols = [];
132
+ let idx = 0;
133
+
134
+ const misValsIds = new Map<string, number[]>();
135
+
136
+ for (let j = 0; j < intCols; ++j) {
137
+ const arr = new Int32Array(rows);
138
+ const name = `int #${j + 1}`;
139
+ const indeces: number[] = [];
140
+
141
+ for (let i = 0; i < rows; ++i)
142
+ arr[i] = Math.floor(Math.random() * MAX_INT);
143
+
144
+ for (let k = 0; k < misValCount; ++k) {
145
+ idx = Math.floor(rows * Math.random());
146
+ arr[idx] = DG.INT_NULL;
147
+ indeces.push(idx);
148
+ }
149
+
150
+ cols.push(DG.Column.fromInt32Array(name, arr));
151
+ misValsIds.set(name, indeces);
152
+ }
153
+
154
+ for (let j = 0; j < floatCols; ++j) {
155
+ const arr = new Float32Array(rows);
156
+ const name = `float #${j + 1}`;
157
+ const indeces: number[] = [];
158
+
159
+ for (let i = 0; i < rows; ++i)
160
+ arr[i] = Math.random() * MAX_FLOAT;
161
+
162
+ for (let k = 0; k < misValCount; ++k) {
163
+ idx = Math.floor(rows * Math.random());
164
+ arr[idx] = DG.FLOAT_NULL;
165
+ indeces.push(idx);
166
+ }
167
+
168
+ cols.push(DG.Column.fromFloat32Array(name, arr));
169
+ misValsIds.set(name, indeces);
170
+ }
171
+
172
+ for (let j = 0; j < strCols; ++j) {
173
+ const arr = new Array<string>(rows);
174
+ const name = `str #${j + 1}`;
175
+ const indeces: number[] = [];
176
+
177
+ for (let i = 0; i < rows; ++i)
178
+ arr[i] = CATEGORIES[Math.floor(Math.random() * catsCount)];
179
+
180
+ const col = DG.Column.fromStrings(name, arr);
181
+
182
+ for (let k = 0; k < misValCount; ++k) {
183
+ idx = Math.floor(rows * Math.random());
184
+ col.set(idx, null);
185
+ indeces.push(idx);
186
+ }
187
+
188
+ cols.push(col);
189
+ misValsIds.set(name, indeces);
190
+ }
191
+
192
+ return {
193
+ df: DG.DataFrame.fromColumns(cols),
194
+ misValsIds: misValsIds,
195
+ };
196
+ } // tableWithMissingVals