@datagrok/eda 1.1.25 → 1.1.28

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.
Files changed (111) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +1 -0
  4. package/dist/05e5e0770f54f07e9474.wasm +0 -0
  5. package/dist/111.js +2 -0
  6. package/dist/111.js.map +1 -0
  7. package/dist/153.js +2 -0
  8. package/dist/153.js.map +1 -0
  9. package/dist/23.js +2 -2
  10. package/dist/23.js.map +1 -0
  11. package/dist/234.js +2 -0
  12. package/dist/234.js.map +1 -0
  13. package/dist/242.js +2 -0
  14. package/dist/242.js.map +1 -0
  15. package/dist/260.js +2 -0
  16. package/dist/260.js.map +1 -0
  17. package/dist/317.js +2 -0
  18. package/dist/317.js.map +1 -0
  19. package/dist/33.js +2 -0
  20. package/dist/33.js.map +1 -0
  21. package/dist/348.js +2 -0
  22. package/dist/348.js.map +1 -0
  23. package/dist/377.js +2 -0
  24. package/dist/377.js.map +1 -0
  25. package/dist/412.js +2 -0
  26. package/dist/412.js.map +1 -0
  27. package/dist/415.js +2 -0
  28. package/dist/415.js.map +1 -0
  29. package/dist/531.js +2 -0
  30. package/dist/531.js.map +1 -0
  31. package/dist/583.js +2 -0
  32. package/dist/583.js.map +1 -0
  33. package/dist/589.js +2 -0
  34. package/dist/589.js.map +1 -0
  35. package/dist/603.js +2 -0
  36. package/dist/603.js.map +1 -0
  37. package/dist/656.js +2 -0
  38. package/dist/656.js.map +1 -0
  39. package/dist/682.js +2 -0
  40. package/dist/682.js.map +1 -0
  41. package/dist/705.js +2 -0
  42. package/dist/705.js.map +1 -0
  43. package/dist/731.js +2 -0
  44. package/dist/731.js.map +1 -0
  45. package/dist/738.js +3 -0
  46. package/dist/738.js.map +1 -0
  47. package/dist/763.js +2 -0
  48. package/dist/763.js.map +1 -0
  49. package/dist/778.js +2 -0
  50. package/dist/778.js.map +1 -0
  51. package/dist/783.js +2 -0
  52. package/dist/783.js.map +1 -0
  53. package/dist/793.js +2 -0
  54. package/dist/793.js.map +1 -0
  55. package/dist/907.js +2 -0
  56. package/dist/907.js.map +1 -0
  57. package/dist/91.js +2 -0
  58. package/dist/91.js.map +1 -0
  59. package/dist/950.js +2 -0
  60. package/dist/950.js.map +1 -0
  61. package/dist/package-test.js +2 -2
  62. package/dist/package-test.js.map +1 -0
  63. package/dist/package.js +2 -2
  64. package/dist/package.js.map +1 -0
  65. package/package.json +92 -92
  66. package/scripts/command.txt +1 -1
  67. package/scripts/func.json +1 -1
  68. package/scripts/module.json +1 -1
  69. package/src/missing-values-imputation/ui.ts +80 -66
  70. package/src/package.ts +288 -38
  71. package/src/pls/pls-tools.ts +16 -15
  72. package/src/regression.ts +232 -0
  73. package/src/svm.ts +78 -38
  74. package/tsconfig.json +4 -4
  75. package/wasm/EDA.js +65 -1
  76. package/wasm/EDA.wasm +0 -0
  77. package/wasm/EDAAPI.js +30 -0
  78. package/wasm/EDAForWebWorker.js +1 -1
  79. package/wasm/callWasm.js +384 -393
  80. package/wasm/regression-api.cpp +66 -0
  81. package/wasm/regression.h +128 -0
  82. package/wasm/workers/fitLinearRegressionParamsWithDataNormalizingWorker.js +13 -0
  83. package/wasm/workers/fitLinearRegressionParamsWorker.js +13 -0
  84. package/webpack.config.js +1 -1
  85. package/dist/208.js +0 -2
  86. package/dist/221.js +0 -2
  87. package/dist/231.js +0 -2
  88. package/dist/261.js +0 -2
  89. package/dist/282.js +0 -2
  90. package/dist/334.js +0 -2
  91. package/dist/356.js +0 -2
  92. package/dist/36.js +0 -2
  93. package/dist/367.js +0 -2
  94. package/dist/374.js +0 -2
  95. package/dist/40.js +0 -2
  96. package/dist/413.js +0 -2
  97. package/dist/42.js +0 -2
  98. package/dist/427.js +0 -2
  99. package/dist/467.js +0 -2
  100. package/dist/523.js +0 -3
  101. package/dist/533.js +0 -2
  102. package/dist/590.js +0 -2
  103. package/dist/65.js +0 -2
  104. package/dist/694.js +0 -2
  105. package/dist/729.js +0 -2
  106. package/dist/796.js +0 -2
  107. package/dist/902.js +0 -2
  108. package/dist/910.js +0 -2
  109. package/dist/972.js +0 -2
  110. package/dist/f5343e2c2e15952ce916.wasm +0 -0
  111. /package/dist/{523.js.LICENSE.txt → 738.js.LICENSE.txt} +0 -0
package/src/package.ts CHANGED
@@ -10,7 +10,7 @@ import {computePCA} from './eda-tools';
10
10
  import {addPrefixToEachColumnName, addOneWayAnovaVizualization} from './eda-ui';
11
11
  import {testDataForBinaryClassification} from './data-generators';
12
12
  import {LINEAR, RBF, POLYNOMIAL, SIGMOID,
13
- getTrainedModel, getPrediction, showTrainReport, getPackedModel} from './svm';
13
+ getTrainedModel, getPrediction, isApplicableSVM, isInteractiveSVM, showTrainReport, getPackedModel} from './svm';
14
14
 
15
15
  import {PLS_ANALYSIS} from './pls/pls-constants';
16
16
  import {runMVA, runDemoMVA, getPlsAnalysis, PlsOutput} from './pls/pls-tools';
@@ -29,6 +29,9 @@ import {DimReductionMethods} from '@datagrok-libraries/ml/src/multi-column-dimen
29
29
  import {runKNNImputer} from './missing-values-imputation/ui';
30
30
  import {MCLEditor} from '@datagrok-libraries/ml/src/MCL/mcl-editor';
31
31
  import {markovCluster} from '@datagrok-libraries/ml/src/MCL/clustering-view';
32
+ import {MCL_OPTIONS_TAG, MCLSerializableOptions} from '@datagrok-libraries/ml/src/MCL';
33
+
34
+ import {getLinearRegressionParams, getPredictionByLinearRegression, getTestDatasetForLinearRegression} from './regression';
32
35
 
33
36
  export const _package = new DG.Package();
34
37
 
@@ -189,7 +192,7 @@ export function GetMCLEditor(call: DG.FuncCall): void {
189
192
  df: params.table, cols: params.columns, metrics: params.distanceMetrics,
190
193
  weights: params.weights, aggregationMethod: params.aggreaggregationMethod, preprocessingFuncs: params.preprocessingFunctions,
191
194
  preprocessingFuncArgs: params.preprocessingFuncArgs, threshold: params.threshold, maxIterations: params.maxIterations,
192
- useWebGPU: params.useWebGPU,
195
+ useWebGPU: params.useWebGPU, inflate: params.inflateFactor,
193
196
  }).call(true);
194
197
  }).show();
195
198
  } catch (err: any) {
@@ -214,13 +217,46 @@ export function GetMCLEditor(call: DG.FuncCall): void {
214
217
  //input: int threshold = 80
215
218
  //input: int maxIterations = 10
216
219
  //input: bool useWebGPU = false
220
+ //input: double inflate = 2
217
221
  //editor: EDA: GetMCLEditor
218
222
  export async function MCL(df: DG.DataFrame, cols: DG.Column[], metrics: KnownMetrics[],
219
223
  weights: number[], aggregationMethod: DistanceAggregationMethod, preprocessingFuncs: (DG.Func | null | undefined)[],
220
- preprocessingFuncArgs: any[], threshold: number = 80, maxIterations: number = 10, useWebGPU: boolean = false,
224
+ preprocessingFuncArgs: any[], threshold: number = 80, maxIterations: number = 10, useWebGPU: boolean = false, inflate: number = 0,
221
225
  ): Promise< DG.ScatterPlotViewer | undefined> {
222
- const res = (await markovCluster(df, cols, metrics, weights,
223
- aggregationMethod, preprocessingFuncs, preprocessingFuncArgs, threshold, maxIterations, useWebGPU));
226
+ const tv = grok.shell.tableView(df.name) ?? grok.shell.addTableView(df);
227
+ const serializedOptions: string = JSON.stringify({
228
+ cols: cols.map((col) => col.name),
229
+ metrics: metrics,
230
+ weights: weights,
231
+ aggregationMethod: aggregationMethod,
232
+ preprocessingFuncs: preprocessingFuncs.map((func) => func?.name ?? null),
233
+ preprocessingFuncArgs: preprocessingFuncArgs,
234
+ threshold: threshold,
235
+ maxIterations: maxIterations,
236
+ useWebGPU: useWebGPU,
237
+ inflate: inflate,
238
+ } satisfies MCLSerializableOptions);
239
+ df.setTag(MCL_OPTIONS_TAG, serializedOptions);
240
+
241
+ const sc = tv.addViewer(DG.VIEWER.SCATTER_PLOT, {title: 'MCL', initializationFunction: 'EDA:MCLInitializationFunction'}) as DG.ScatterPlotViewer;
242
+ return sc;
243
+ }
244
+
245
+ //name: MCLInitializationFunction
246
+ //input: viewer sc
247
+ export async function MCLInitializationFunction(sc: DG.ScatterPlotViewer) {
248
+ const df = sc.dataFrame;
249
+ if (df === null)
250
+ throw new Error('Data frame of the scatter plot is null');
251
+ const mclTag = df.getTag(MCL_OPTIONS_TAG);
252
+ if (!mclTag)
253
+ throw new Error('MCL options tag on the dataFrame is not found');
254
+ const options: MCLSerializableOptions = JSON.parse(mclTag);
255
+ const cols = options.cols.map((colName) => df.columns.byName(colName));
256
+ const preprocessingFuncs = options.preprocessingFuncs.map((funcName) => funcName ? DG.Func.byName(funcName) : null);
257
+ const res = await markovCluster(df, cols, options.metrics, options.weights,
258
+ options.aggregationMethod, preprocessingFuncs, options.preprocessingFuncArgs, options.threshold,
259
+ options.maxIterations, options.useWebGPU, options.inflate, sc);
224
260
  return res?.sc;
225
261
  }
226
262
 
@@ -298,17 +334,12 @@ export async function testDataLinearNonSeparable(name: string, sigma: number, sa
298
334
  //meta.mlname: linear kernel LS-SVM
299
335
  //meta.mlrole: train
300
336
  //input: dataframe df
301
- //input: string predict_column
337
+ //input: column predictColumn
302
338
  //input: double gamma = 1.0 {category: Hyperparameters}
303
- //input: bool toShowReport = false {caption: to show report; category: Report}
304
339
  //output: dynamic model
305
- export async function trainLinearKernelSVM(df: DG.DataFrame, predict_column: string,
306
- gamma: number, toShowReport: boolean): Promise<any> {
307
- const trainedModel = await getTrainedModel({gamma: gamma, kernel: LINEAR}, df, predict_column);
308
-
309
- if (toShowReport)
310
- showTrainReport(df, trainedModel);
311
-
340
+ export async function trainLinearKernelSVM(df: DG.DataFrame, predictColumn: DG.Column,
341
+ gamma: number): Promise<any> {
342
+ const trainedModel = await getTrainedModel({gamma: gamma, kernel: LINEAR}, df, predictColumn);
312
343
  return getPackedModel(trainedModel);
313
344
  }
314
345
 
@@ -322,23 +353,52 @@ export async function applyLinearKernelSVM(df: DG.DataFrame, model: any): Promis
322
353
  return await getPrediction(df, model);
323
354
  }
324
355
 
356
+ //name: isApplicableLinearKernelSVM
357
+ //meta.mlname: linear kernel LS-SVM
358
+ //meta.mlrole: isApplicable
359
+ //input: dataframe df
360
+ //input: column predictColumn
361
+ //output: bool result
362
+ export async function isApplicableLinearKernelSVM(df: DG.DataFrame, predictColumn: DG.Column): Promise<boolean> {
363
+ return isApplicableSVM(df, predictColumn);
364
+ }
365
+
366
+ //name: isInteractiveLinearKernelSVM
367
+ //meta.mlname: linear kernel LS-SVM
368
+ //meta.mlrole: isInteractive
369
+ //input: dataframe df
370
+ //input: column predictColumn
371
+ //output: bool result
372
+ export async function isInteractiveLinearKernelSVM(df: DG.DataFrame, predictColumn: DG.Column): Promise<boolean> {
373
+ return isInteractiveSVM(df, predictColumn);
374
+ }
375
+
376
+ //name: visualizeLinearKernelSVM
377
+ //meta.mlname: linear kernel LS-SVM
378
+ //meta.mlrole: visualize
379
+ //input: dataframe df
380
+ //input: column targetColumn
381
+ //input: column predictColumn
382
+ //input: dynamic model
383
+ //output: dynamic widget
384
+ export async function visualizeLinearKernelSVM(df: DG.DataFrame, targetColumn: DG.Column, predictColumn: DG.Column, model: any): Promise<any> {
385
+ return showTrainReport(df, model);
386
+ }
387
+
388
+
325
389
  //name: trainRBFkernelSVM
326
390
  //meta.mlname: RBF-kernel LS-SVM
327
391
  //meta.mlrole: train
328
392
  //input: dataframe df
329
- //input: string predict_column
393
+ //input: column predictColumn
330
394
  //input: double gamma = 1.0 {category: Hyperparameters}
331
395
  //input: double sigma = 1.5 {category: Hyperparameters}
332
- //input: bool toShowReport = false {caption: to show report; category: Report}
333
396
  //output: dynamic model
334
- export async function trainRBFkernelSVM(df: DG.DataFrame, predict_column: string,
335
- gamma: number, sigma: number, toShowReport: boolean): Promise<any> {
397
+ export async function trainRBFkernelSVM(df: DG.DataFrame, predictColumn: DG.Column,
398
+ gamma: number, sigma: number): Promise<any> {
336
399
  const trainedModel = await getTrainedModel(
337
400
  {gamma: gamma, kernel: RBF, sigma: sigma},
338
- df, predict_column);
339
-
340
- if (toShowReport)
341
- showTrainReport(df, trainedModel);
401
+ df, predictColumn);
342
402
 
343
403
  return getPackedModel(trainedModel);
344
404
  }
@@ -353,24 +413,53 @@ export async function applyRBFkernelSVM(df: DG.DataFrame, model: any): Promise<D
353
413
  return await getPrediction(df, model);
354
414
  }
355
415
 
416
+ //name: isApplicableRBFkernelSVM
417
+ //meta.mlname: RBF-kernel LS-SVM
418
+ //meta.mlrole: isApplicable
419
+ //input: dataframe df
420
+ //input: column predictColumn
421
+ //output: bool result
422
+ export async function isApplicableRBFkernelSVM(df: DG.DataFrame, predictColumn: DG.Column): Promise<boolean> {
423
+ return isApplicableSVM(df, predictColumn);
424
+ }
425
+
426
+ //name: isInteractiveRBFkernelSVM
427
+ //meta.mlname: RBF-kernel LS-SVM
428
+ //meta.mlrole: isInteractive
429
+ //input: dataframe df
430
+ //input: column predictColumn
431
+ //output: bool result
432
+ export async function isInteractiveRBFkernelSVM(df: DG.DataFrame, predictColumn: DG.Column): Promise<boolean> {
433
+ return isInteractiveSVM(df, predictColumn);
434
+ }
435
+
436
+
437
+ //name: visualizeRBFkernelSVM
438
+ //meta.mlname: RBF-kernel LS-SVM
439
+ //meta.mlrole: visualize
440
+ //input: dataframe df
441
+ //input: column targetColumn
442
+ //input: column predictColumn
443
+ //input: dynamic model
444
+ //output: dynamic widget
445
+ export async function visualizeRBFkernelSVM(df: DG.DataFrame, targetColumn: DG.Column, predictColumn: DG.Column, model: any): Promise<any> {
446
+ return showTrainReport(df, model);
447
+ }
448
+
356
449
  //name: trainPolynomialKernelSVM
357
450
  //meta.mlname: polynomial kernel LS-SVM
358
451
  //meta.mlrole: train
359
452
  //input: dataframe df
360
- //input: string predict_column
453
+ //input: column predictColumn
361
454
  //input: double gamma = 1.0 {category: Hyperparameters}
362
455
  //input: double c = 1 {category: Hyperparameters}
363
456
  //input: double d = 2 {category: Hyperparameters}
364
- //input: bool toShowReport = false {caption: to show report; category: Report}
365
457
  //output: dynamic model
366
- export async function trainPolynomialKernelSVM(df: DG.DataFrame, predict_column: string,
367
- gamma: number, c: number, d: number, toShowReport: boolean): Promise<any> {
458
+ export async function trainPolynomialKernelSVM(df: DG.DataFrame, predictColumn: DG.Column,
459
+ gamma: number, c: number, d: number): Promise<any> {
368
460
  const trainedModel = await getTrainedModel(
369
461
  {gamma: gamma, kernel: POLYNOMIAL, cParam: c, dParam: d},
370
- df, predict_column);
371
-
372
- if (toShowReport)
373
- showTrainReport(df, trainedModel);
462
+ df, predictColumn);
374
463
 
375
464
  return getPackedModel(trainedModel);
376
465
  } // trainPolynomialKernelSVM
@@ -385,24 +474,52 @@ export async function applyPolynomialKernelSVM(df: DG.DataFrame, model: any): Pr
385
474
  return await getPrediction(df, model);
386
475
  }
387
476
 
477
+ //name: isApplicablePolynomialKernelSVM
478
+ //meta.mlname: polynomial kernel LS-SVM
479
+ //meta.mlrole: isApplicable
480
+ //input: dataframe df
481
+ //input: column predictColumn
482
+ //output: bool result
483
+ export async function isApplicablePolynomialKernelSVM(df: DG.DataFrame, predictColumn: DG.Column): Promise<boolean> {
484
+ return isApplicableSVM(df, predictColumn);
485
+ }
486
+
487
+ //name: isInteractivePolynomialKernelSVM
488
+ //meta.mlname: polynomial kernel LS-SVM
489
+ //meta.mlrole: isInteractive
490
+ //input: dataframe df
491
+ //input: column predictColumn
492
+ //output: bool result
493
+ export async function isInteractivePolynomialKernelSVM(df: DG.DataFrame, predictColumn: DG.Column): Promise<boolean> {
494
+ return isInteractiveSVM(df, predictColumn);
495
+ }
496
+
497
+ //name: visualizePolynomialKernelSVM
498
+ //meta.mlname: polynomial kernel LS-SVM
499
+ //meta.mlrole: visualize
500
+ //input: dataframe df
501
+ //input: column targetColumn
502
+ //input: column predictColumn
503
+ //input: dynamic model
504
+ //output: dynamic widget
505
+ export async function visualizePolynomialKernelSVM(df: DG.DataFrame, targetColumn: DG.Column, predictColumn: DG.Column, model: any): Promise<any> {
506
+ return showTrainReport(df, model);
507
+ }
508
+
388
509
  //name: trainSigmoidKernelSVM
389
510
  //meta.mlname: sigmoid kernel LS-SVM
390
511
  //meta.mlrole: train
391
512
  //input: dataframe df
392
- //input: string predict_column
513
+ //input: column predictColumn
393
514
  //input: double gamma = 1.0 {category: Hyperparameters}
394
515
  //input: double kappa = 1 {category: Hyperparameters}
395
516
  //input: double theta = 1 {category: Hyperparameters}
396
- //input: bool toShowReport = false {caption: to show report; category: Report}
397
517
  //output: dynamic model
398
- export async function trainSigmoidKernelSVM(df: DG.DataFrame, predict_column: string,
399
- gamma: number, kappa: number, theta: number, toShowReport: boolean): Promise<any> {
518
+ export async function trainSigmoidKernelSVM(df: DG.DataFrame, predictColumn: DG.Column,
519
+ gamma: number, kappa: number, theta: number): Promise<any> {
400
520
  const trainedModel = await getTrainedModel(
401
521
  {gamma: gamma, kernel: SIGMOID, kappa: kappa, theta: theta},
402
- df, predict_column);
403
-
404
- if (toShowReport)
405
- showTrainReport(df, trainedModel);
522
+ df, predictColumn);
406
523
 
407
524
  return getPackedModel(trainedModel);
408
525
  } // trainSigmoidKernelSVM
@@ -417,6 +534,38 @@ export async function applySigmoidKernelSVM(df: DG.DataFrame, model: any): Promi
417
534
  return await getPrediction(df, model);
418
535
  }
419
536
 
537
+ //name: isApplicableSigmoidKernelSVM
538
+ //meta.mlname: sigmoid kernel LS-SVM
539
+ //meta.mlrole: isApplicable
540
+ //input: dataframe df
541
+ //input: column predictColumn
542
+ //output: bool result
543
+ export async function isApplicableSigmoidKernelSVM(df: DG.DataFrame, predictColumn: DG.Column): Promise<boolean> {
544
+ return isApplicableSVM(df, predictColumn);
545
+ }
546
+
547
+ //name: isInteractiveSigmoidKernelSVM
548
+ //meta.mlname: sigmoid kernel LS-SVM
549
+ //meta.mlrole: isInteractive
550
+ //input: dataframe df
551
+ //input: column predictColumn
552
+ //output: bool result
553
+ export async function isInteractiveSigmoidKernelSVM(df: DG.DataFrame, predictColumn: DG.Column): Promise<boolean> {
554
+ return isInteractiveSVM(df, predictColumn);
555
+ }
556
+
557
+ //name: visualizeSigmoidKernelSVM
558
+ //meta.mlname: sigmoid kernel LS-SVM
559
+ //meta.mlrole: visualize
560
+ //input: dataframe df
561
+ //input: column targetColumn
562
+ //input: column predictColumn
563
+ //input: dynamic model
564
+ //output: dynamic widget
565
+ export async function visualizeSigmoidKernelSVM(df: DG.DataFrame, targetColumn: DG.Column, predictColumn: DG.Column, model: any): Promise<any> {
566
+ return showTrainReport(df, model);
567
+ }
568
+
420
569
  //top-menu: ML | Analyze | ANOVA...
421
570
  //name: ANOVA
422
571
  //description: One-way analysis of variances (ANOVA) determines whether the examined factor has a significant impact on the studied feature.
@@ -436,3 +585,104 @@ export function anova(table: DG.DataFrame, factor: DG.Column, feature: DG.Column
436
585
  export function kNNImputation() {
437
586
  runKNNImputer();
438
587
  }
588
+
589
+ //name: KNN imputation for a table
590
+ //desription: Missing values imputation using the k-nearest neighbors method for a given table
591
+ //input: dataframe table
592
+ export async function kNNImputationForTable(table: DG.DataFrame) {
593
+ await runKNNImputer(table);
594
+ }
595
+
596
+ //name: linearRegression
597
+ //description: Linear Regression demo
598
+ //input: dataframe table
599
+ //input: column_list features {type: numerical}
600
+ //input: column target {type: numerical}
601
+ //input: bool plot = true {caption: plot}
602
+ export async function linearRegression(table: DG.DataFrame, features: DG.ColumnList, target: DG.Column, plot: boolean): Promise<void> {
603
+ const t1 = performance.now();
604
+ const params = await getLinearRegressionParams(features, target);
605
+ const t2 = performance.now();
606
+ console.log(`Fit: ${t2 - t1} ms.`);
607
+ const prediction = getPredictionByLinearRegression(features, params);
608
+ console.log(`Predict: ${performance.now() - t2} ms.`);
609
+
610
+ prediction.name = table.columns.getUnusedName(prediction.name);
611
+
612
+ table.columns.add(prediction);
613
+
614
+ if (plot) {
615
+ const view = grok.shell.tableView(table.name);
616
+ view.addViewer(DG.VIEWER.SCATTER_PLOT, {
617
+ xColumnName: target.name,
618
+ yColumnName: prediction.name,
619
+ showRegressionLine: true,
620
+ });
621
+ }
622
+ }
623
+
624
+ //name: generateDatasetForLinearRegressionTest
625
+ //description: Create demo dataset for linear regression
626
+ //input: int rowCount = 10000 {min: 1000; max: 10000000; step: 10000}
627
+ //input: int colCount = 10 {min: 1; max: 1000; step: 10}
628
+ //input: double featuresScale = 10 {min: -1000; max: 1000; step: 10}
629
+ //input: double featuresBias = 10 {min: -1000; max: 1000; step: 10}
630
+ //input: double paramsScale = 10 {min: -1000; max: 1000; step: 10}
631
+ //input: double paramsBias = 10 {min: -1000; max: 1000; step: 10}
632
+ //output: dataframe table
633
+ export function generateDatasetForLinearRegressionTest(rowCount: number, colCount: number,
634
+ featuresScale: number, featuresBias: number, paramsScale: number, paramsBias: number): DG.DataFrame {
635
+ return getTestDatasetForLinearRegression(rowCount, colCount, featuresScale, featuresBias, paramsScale, paramsBias);
636
+ }
637
+
638
+ //name: trainLinearRegression
639
+ //meta.mlname: Linear Regression
640
+ //meta.mlrole: train
641
+ //input: dataframe df
642
+ //input: column predictColumn
643
+ //output: dynamic model
644
+ export async function trainLinearRegression(df: DG.DataFrame, predictColumn: DG.Column): Promise<Uint8Array> {
645
+ const features = df.columns;
646
+ const params = await getLinearRegressionParams(features, predictColumn);
647
+
648
+ return new Uint8Array(params.buffer);
649
+ }
650
+
651
+ //name: applyLinearRegression
652
+ //meta.mlname: Linear Regression
653
+ //meta.mlrole: apply
654
+ //input: dataframe df
655
+ //input: dynamic model
656
+ //output: dataframe table
657
+ export function applyLinearRegression(df: DG.DataFrame, model: any): DG.DataFrame {
658
+ const features = df.columns;
659
+ const params = new Float32Array((model as Uint8Array).buffer);
660
+ return DG.DataFrame.fromColumns([getPredictionByLinearRegression(features, params)]);
661
+ }
662
+
663
+ //name: isApplicableLinearRegression
664
+ //meta.mlname: Linear Regression
665
+ //meta.mlrole: isApplicable
666
+ //input: dataframe df
667
+ //input: column predictColumn
668
+ //output: bool result
669
+ export function isApplicableLinearRegression(df: DG.DataFrame, predictColumn: DG.Column): boolean {
670
+ for (const col of df.columns) {
671
+ if (!col.matches('numerical'))
672
+ return false;
673
+ }
674
+ if (!predictColumn.matches('numerical'))
675
+ return false;
676
+
677
+ return true;
678
+ }
679
+
680
+ //name: isInteractiveLinearRegression
681
+ //meta.mlname: Linear Regression
682
+ //meta.mlrole: isInteractive
683
+ //input: dataframe df
684
+ //input: column predictColumn
685
+ //output: bool result
686
+ export function isInteractiveLinearRegression(df: DG.DataFrame, predictColumn: DG.Column): boolean {
687
+ return df.rowCount <= 100000;
688
+ }
@@ -6,7 +6,7 @@ import * as DG from 'datagrok-api/dg';
6
6
 
7
7
  import {PLS_ANALYSIS, ERROR_MSG, TITLE, HINT, LINK, COMPONENTS, INT, TIMEOUT,
8
8
  RESULT_NAMES, WASM_OUTPUT_IDX, RADIUS, LINE_WIDTH, COLOR, X_COORD, Y_COORD,
9
- DEMO_INTRO_MD, DEMO_RESULTS_MD, DELAY, DEMO_RESULTS} from './pls-constants';
9
+ DEMO_INTRO_MD, DEMO_RESULTS_MD, DEMO_RESULTS} from './pls-constants';
10
10
  import {checkWasmDimensionReducerInputs, checkColumnType, checkMissingVals} from '../utils';
11
11
  import {_partialLeastSquareRegressionInWebWorker} from '../../wasm/EDAAPI';
12
12
  import {carsDataframe} from '../data-generators';
@@ -141,7 +141,7 @@ async function performMVA(input: PlsInput, analysisType: PLS_ANALYSIS): Promise<
141
141
  const scoresScatter = DG.Viewer.scatterPlot(input.table, {
142
142
  title: TITLE.SCORES,
143
143
  xColumnName: plsCols[0].name,
144
- yColumnName: (plsCols.length > 1) ? plsCols[1].name : result.uScores[0],
144
+ yColumnName: (plsCols.length > 1) ? plsCols[1].name : result.uScores[0].name,
145
145
  markerType: DG.MARKER_TYPE.CIRCLE,
146
146
  labels: input.names?.name,
147
147
  help: LINK.SCORES,
@@ -161,7 +161,8 @@ async function performMVA(input: PlsInput, analysisType: PLS_ANALYSIS): Promise<
161
161
  min: -radius,
162
162
  max: radius,
163
163
  color: COLOR.CIRCLE,
164
- })};
164
+ });
165
+ };
165
166
 
166
167
  scoreNames.forEach((xName) => {
167
168
  const x = '${' + xName + '}';
@@ -226,12 +227,13 @@ async function performMVA(input: PlsInput, analysisType: PLS_ANALYSIS): Promise<
226
227
 
227
228
  // emphasize viewers in the demo case
228
229
  if (analysisType === PLS_ANALYSIS.DEMO) {
229
- const pages = [predictVsReferScatter, scoresScatter, loadingsScatter, regrCoeffsBar, explVarsBar].map((viewer, idx) => {
230
- return {
231
- text: DEMO_RESULTS[idx].text,
232
- showNextTo: viewer.root,
233
- }
234
- });
230
+ const pages = [predictVsReferScatter, scoresScatter, loadingsScatter, regrCoeffsBar, explVarsBar]
231
+ .map((viewer, idx) => {
232
+ return {
233
+ text: DEMO_RESULTS[idx].text,
234
+ showNextTo: viewer.root,
235
+ };
236
+ });
235
237
 
236
238
  const wizard = ui.hints.addTextHint({title: TITLE.EXPLORE, pages: pages});
237
239
  wizard.helpUrl = LINK.MVA;
@@ -281,17 +283,16 @@ export async function runMVA(analysisType: PLS_ANALYSIS): Promise<void> {
281
283
 
282
284
  // responce (to predict)
283
285
  let predict = numCols[numCols.length - 1];
284
- const predictInput = ui.columnInput(TITLE.PREDICT, table, predict, () => {
286
+ const predictInput = ui.input.column(TITLE.PREDICT, {table: table, value: predict, onValueChanged: () => {
285
287
  predict = predictInput.value!;
286
288
  updateIputs();
287
- },
288
- {filter: (col: DG.Column) => isValidNumeric(col)},
289
+ }, filter: (col: DG.Column) => isValidNumeric(col)},
289
290
  );
290
291
  predictInput.setTooltip(HINT.PREDICT);
291
292
 
292
293
  // predictors (features)
293
294
  let features: DG.Column[];
294
- const featuresInput = ui.columnsInput(TITLE.USING, table, () => {}, {available: numColNames});
295
+ const featuresInput = ui.input.columns(TITLE.USING, {table: table, available: numColNames});
295
296
  featuresInput.onInput(() => updateIputs());
296
297
  featuresInput.setTooltip(HINT.FEATURES);
297
298
 
@@ -334,8 +335,8 @@ export async function runMVA(analysisType: PLS_ANALYSIS): Promise<void> {
334
335
 
335
336
  // names of samples
336
337
  let names = (strCols.length > 0) ? strCols[0] : null;
337
- const namesInputs = ui.columnInput(TITLE.NAMES, table, names, () => names = predictInput.value,
338
- {filter: (col: DG.Column) => col.type === DG.COLUMN_TYPE.STRING},
338
+ const namesInputs = ui.input.column(TITLE.NAMES, {table: table, value: names!, onValueChanged: () => names = predictInput.value,
339
+ filter: (col: DG.Column) => col.type === DG.COLUMN_TYPE.STRING},
339
340
  );
340
341
  namesInputs.setTooltip(HINT.NAMES);
341
342
  namesInputs.root.hidden = (strCols.length === 0) || (analysisType === PLS_ANALYSIS.COMPUTE_COMPONENTS);