@datagrok/eda 1.1.8 → 1.1.10
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.
- package/.eslintignore +1 -0
- package/.eslintrc.json +45 -0
- package/dist/100.js +2 -2
- package/dist/118.js +2 -2
- package/dist/{645.js → 208.js} +2 -2
- package/dist/221.js +1 -1
- package/dist/261.js +2 -0
- package/dist/334.js +2 -0
- package/dist/352.js +2 -0
- package/dist/361.js +2 -0
- package/dist/{604.js → 367.js} +2 -2
- package/dist/{584.js → 374.js} +2 -2
- package/dist/42.js +2 -0
- package/dist/{111.js → 467.js} +2 -2
- package/dist/471.js +2 -2
- package/dist/483.js +2 -0
- package/dist/{632.js → 533.js} +2 -2
- package/dist/664.js +2 -2
- package/dist/694.js +2 -2
- package/dist/729.js +1 -1
- package/dist/{146.js → 902.js} +2 -2
- package/dist/910.js +2 -0
- package/dist/943.js +3 -0
- package/dist/package-test.js +2 -2
- package/dist/package.js +2 -2
- package/package.json +10 -4
- package/src/data-generators.ts +13 -13
- package/src/eda-tools.ts +42 -83
- package/src/eda-ui.ts +65 -58
- package/src/package-test.ts +2 -2
- package/src/package.ts +53 -61
- package/src/stat-tools.ts +72 -61
- package/src/svm.ts +144 -151
- package/src/utils.ts +13 -17
- package/src/workers/tsne-worker.ts +6 -6
- package/src/workers/umap-worker.ts +3 -3
- package/webpack.config.js +3 -2
- package/dist/155.js +0 -2
- package/dist/313.js +0 -2
- package/dist/355.js +0 -2
- package/dist/44.js +0 -2
- package/dist/489.js +0 -3
- package/dist/656.js +0 -2
- package/dist/727.js +0 -2
- package/dist/861.js +0 -2
- package/dist/93.js +0 -2
- package/dist/972.js +0 -2
- /package/dist/{489.js.LICENSE.txt → 943.js.LICENSE.txt} +0 -0
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/eda",
|
|
3
3
|
"friendlyName": "EDA",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.10",
|
|
5
5
|
"description": "Exploratory Data Analysis Tools",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@datagrok-libraries/ml": "^6.
|
|
7
|
+
"@datagrok-libraries/ml": "^6.4.1",
|
|
8
8
|
"@datagrok-libraries/tutorials": "^1.3.6",
|
|
9
9
|
"@datagrok-libraries/utils": "^4.1.4",
|
|
10
10
|
"@datagrok-libraries/math": "^1.0.7",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
"datagrok-api": "^1.16.0",
|
|
14
14
|
"dayjs": "^1.11.9",
|
|
15
15
|
"jstat": "^1.9.6",
|
|
16
|
-
"umap-js": "^1.3.3"
|
|
16
|
+
"umap-js": "^1.3.3",
|
|
17
|
+
"worker-loader": "latest",
|
|
18
|
+
"source-map-loader": "^4.0.1"
|
|
17
19
|
},
|
|
18
20
|
"author": {
|
|
19
21
|
"name": "Viktor Makarichev",
|
|
@@ -23,7 +25,11 @@
|
|
|
23
25
|
"ts-loader": "latest",
|
|
24
26
|
"typescript": "latest",
|
|
25
27
|
"webpack": "latest",
|
|
26
|
-
"webpack-cli": "latest"
|
|
28
|
+
"webpack-cli": "latest",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
|
30
|
+
"@typescript-eslint/parser": "^5.32.0",
|
|
31
|
+
"eslint": "^8.21.0",
|
|
32
|
+
"eslint-config-google": "^0.14.0"
|
|
27
33
|
},
|
|
28
34
|
"scripts": {
|
|
29
35
|
"link-all": "npm link datagrok-api @datagrok-libraries/utils @datagrok-libraries/tutorials",
|
package/src/data-generators.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
1
2
|
// Test data generation tools
|
|
2
3
|
|
|
3
4
|
/* Do not change these import lines to match external modules in webpack configuration */
|
|
@@ -21,7 +22,7 @@ export function carsDataframe(): DG.DataFrame {
|
|
|
21
22
|
DG.Column.fromInt32Array('diesel', new Int32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1])),
|
|
22
23
|
DG.Column.fromInt32Array('turbo', new Int32Array([0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1])),
|
|
23
24
|
DG.Column.fromInt32Array('two.doors', new Int32Array([1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0])),
|
|
24
|
-
DG.Column.fromInt32Array('hatchback', new Int32Array([1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0])),
|
|
25
|
+
DG.Column.fromInt32Array('hatchback', new Int32Array([1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0])),
|
|
25
26
|
DG.Column.fromFloat32Array('wheel.base', new Float32Array([94.5, 105.80000305175781, 101.19999694824219, 94.5, 93.69999694824219, 93.69999694824219, 93.69999694824219, 96.5, 94.30000305175781, 113, 93.0999984741211, 115.5999984741211, 102.69999694824219, 93.69999694824219, 94.5, 94.5, 93.69999694824219, 114.19999694824219, 89.5, 99.0999984741211, 97.19999694824219, 95.69999694824219, 95.69999694824219, 98.4000015258789, 102.4000015258789, 97.30000305175781, 100.4000015258789, 104.30000305175781, 109.0999984741211, 109.0999984741211])),
|
|
26
27
|
DG.Column.fromFloat32Array('length', new Float32Array([171.1999969482422, 192.6999969482422, 176.8000030517578, 158.8000030517578, 157.3000030517578, 157.3000030517578, 150, 175.39999389648438, 170.6999969482422, 199.60000610351562, 166.8000030517578, 202.60000610351562, 178.39999389648438, 157.3000030517578, 170.1999969482422, 165.3000030517578, 157.3000030517578, 198.89999389648438, 168.89999389648438, 186.60000610351562, 172, 158.6999969482422, 166.3000030517578, 176.1999969482422, 175.60000610351562, 171.6999969482422, 180.1999969482422, 188.8000030517578, 188.8000030517578, 188.8000030517578])),
|
|
27
28
|
DG.Column.fromFloat32Array('width', new Float32Array([65.5, 71.4000015258789, 64.80000305175781, 63.599998474121094, 63.79999923706055, 63.79999923706055, 64, 65.19999694824219, 61.79999923706055, 69.5999984741211, 64.19999694824219, 71.69999694824219, 68, 64.4000015258789, 63.79999923706055, 63.79999923706055, 63.79999923706055, 68.4000015258789, 65, 66.5, 65.4000015258789, 63.599998474121094, 64.4000015258789, 65.5999984741211, 66.5, 65.5, 66.9000015258789, 67.19999694824219, 68.80000305175781, 68.9000015258789])),
|
|
@@ -38,36 +39,35 @@ export function carsDataframe(): DG.DataFrame {
|
|
|
38
39
|
} // carsDataframe
|
|
39
40
|
|
|
40
41
|
// Generate dataset for testing binary classifiers
|
|
41
|
-
export async function testDataForBinaryClassification(kernel: number, kernelParams: Array<number>,
|
|
42
|
-
name: string, samplesCount: number, featuresCount: number, min: number,
|
|
42
|
+
export async function testDataForBinaryClassification(kernel: number, kernelParams: Array<number>,
|
|
43
|
+
name: string, samplesCount: number, featuresCount: number, min: number,
|
|
43
44
|
max: number, violatorsPercentage: number): Promise<DG.DataFrame> {
|
|
44
|
-
|
|
45
45
|
// check inputs
|
|
46
46
|
checkGeneratorSVMinputs(samplesCount, featuresCount, min, max, violatorsPercentage);
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
// kernel params column
|
|
49
49
|
const kernelParamsCol = DG.Column.fromList('double', 'kernelParams', kernelParams);
|
|
50
|
-
|
|
51
|
-
// CALL WASM-COMPUTATIONS
|
|
50
|
+
|
|
51
|
+
// CALL WASM-COMPUTATIONS
|
|
52
52
|
let _output: any;
|
|
53
|
-
|
|
53
|
+
const _promise = _generateDatasetInWebWorker(kernel, kernelParamsCol,
|
|
54
54
|
samplesCount, featuresCount, min, max, violatorsPercentage);
|
|
55
55
|
|
|
56
56
|
await _promise.then(
|
|
57
|
-
_result => {
|
|
58
|
-
_error => {
|
|
57
|
+
(_result) => {_output = _result;},
|
|
58
|
+
(_error) => {throw new Error(`Error: ${_error}`);},
|
|
59
59
|
);
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
// Rename labels column
|
|
62
62
|
_output[SVM_GEN_LABELS_INDEX].name = SVM_LABEL_NAME;
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
// Rename feature columns
|
|
65
65
|
for (const col of _output[SVM_GEN_FEATURES_INDEX])
|
|
66
66
|
col.name = SVM_FEATURE_NAME + col.name;
|
|
67
67
|
|
|
68
68
|
// Create dataframe
|
|
69
69
|
const df = DG.DataFrame.fromColumns(_output[SVM_GEN_FEATURES_INDEX]);
|
|
70
|
-
df.name = name;
|
|
70
|
+
df.name = name;
|
|
71
71
|
df.columns.add(_output[SVM_GEN_LABELS_INDEX]);
|
|
72
72
|
|
|
73
73
|
return df;
|
package/src/eda-tools.ts
CHANGED
|
@@ -4,30 +4,27 @@ import * as grok from 'datagrok-api/grok';
|
|
|
4
4
|
import * as ui from 'datagrok-api/ui';
|
|
5
5
|
import * as DG from 'datagrok-api/dg';
|
|
6
6
|
|
|
7
|
-
import {DimensionalityReducer} from '@datagrok-libraries/ml/src/reduce-dimensionality';
|
|
8
|
-
import {VectorMetricsNames} from '@datagrok-libraries/ml/src/typed-metrics';
|
|
9
|
-
|
|
10
7
|
import {_principalComponentAnalysisInWebWorker,
|
|
11
8
|
_partialLeastSquareRegressionInWebWorker} from '../wasm/EDAAPI';
|
|
12
9
|
|
|
13
|
-
import {checkWasmDimensionReducerInputs, checkUMAPinputs, checkTSNEinputs,
|
|
10
|
+
import {checkWasmDimensionReducerInputs, checkUMAPinputs, checkTSNEinputs,
|
|
14
11
|
getRowsOfNumericalColumnns} from './utils';
|
|
15
12
|
|
|
16
13
|
// Principal components analysis (PCA)
|
|
17
14
|
export async function computePCA(table: DG.DataFrame, features: DG.ColumnList, components: number,
|
|
18
|
-
center: boolean, scale: boolean): Promise<DG.DataFrame>
|
|
19
|
-
{
|
|
15
|
+
center: boolean, scale: boolean): Promise<DG.DataFrame> {
|
|
20
16
|
checkWasmDimensionReducerInputs(features, components);
|
|
21
17
|
|
|
22
18
|
const centerNum = center ? 1 : 0;
|
|
23
19
|
const scaleNum = scale ? 1 : 0;
|
|
24
20
|
|
|
25
21
|
return await _principalComponentAnalysisInWebWorker(table, features, components, centerNum, scaleNum);
|
|
26
|
-
}
|
|
22
|
+
}
|
|
27
23
|
|
|
28
24
|
// Partial least square regression (PLS)
|
|
29
|
-
export async function computePLS(
|
|
30
|
-
|
|
25
|
+
export async function computePLS(
|
|
26
|
+
table: DG.DataFrame, features: DG.ColumnList, predict: DG.Column, components: number,
|
|
27
|
+
): Promise<any> {
|
|
31
28
|
// Inputs are checked in the same manner as in PCA, since the same computations are applied.
|
|
32
29
|
checkWasmDimensionReducerInputs(features, components);
|
|
33
30
|
|
|
@@ -36,10 +33,9 @@ export async function computePLS(table: DG.DataFrame, features: DG.ColumnList, p
|
|
|
36
33
|
|
|
37
34
|
// Uniform Manifold Approximation and Projection (UMAP)
|
|
38
35
|
export async function computeUMAP(features: DG.ColumnList, components: number, epochs: number,
|
|
39
|
-
neighbors: number, minDist: number, spread: number): Promise<DG.DataFrame>
|
|
40
|
-
{
|
|
36
|
+
neighbors: number, minDist: number, spread: number): Promise<DG.DataFrame> {
|
|
41
37
|
// check inputs
|
|
42
|
-
checkUMAPinputs(features, components, epochs, neighbors, minDist, spread);
|
|
38
|
+
checkUMAPinputs(features, components, epochs, neighbors, minDist, spread);
|
|
43
39
|
|
|
44
40
|
// get row-by-row data
|
|
45
41
|
const data = getRowsOfNumericalColumnns(features);
|
|
@@ -47,27 +43,28 @@ export async function computeUMAP(features: DG.ColumnList, components: number, e
|
|
|
47
43
|
let workerOutput: any;
|
|
48
44
|
|
|
49
45
|
// UMAP in webworker
|
|
50
|
-
|
|
46
|
+
const promise = new Promise((resolve, _reject) => {
|
|
51
47
|
const worker = new Worker(new URL('workers/umap-worker.ts', import.meta.url));
|
|
52
|
-
|
|
48
|
+
|
|
53
49
|
worker.postMessage({
|
|
54
|
-
data: data,
|
|
50
|
+
data: data,
|
|
55
51
|
options: {
|
|
56
52
|
nComponents: components,
|
|
57
53
|
nEpochs: epochs,
|
|
58
54
|
nNeighbors: neighbors,
|
|
59
55
|
minDist: minDist,
|
|
60
|
-
spread: spread
|
|
61
|
-
|
|
56
|
+
spread: spread,
|
|
57
|
+
}});
|
|
62
58
|
|
|
63
59
|
worker.onmessage = function(e) {
|
|
64
60
|
worker.terminate();
|
|
65
|
-
resolve(e.data.embeddings);
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
resolve(e.data.embeddings);
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
|
|
68
65
|
await promise.then(
|
|
69
|
-
result => {
|
|
70
|
-
|
|
66
|
+
(result) => {workerOutput = result;},
|
|
67
|
+
(_error) => {throw new Error('applying UMAP fails.');},
|
|
71
68
|
);
|
|
72
69
|
|
|
73
70
|
const embeddings = workerOutput as number[][];
|
|
@@ -77,22 +74,22 @@ export async function computeUMAP(features: DG.ColumnList, components: number, e
|
|
|
77
74
|
// Create output
|
|
78
75
|
|
|
79
76
|
// columns data
|
|
80
|
-
const umapColumnsData = range.map(_ => new Float32Array(rowCount));
|
|
77
|
+
const umapColumnsData = range.map((_) => new Float32Array(rowCount));
|
|
81
78
|
|
|
82
79
|
// perform transponation
|
|
83
|
-
for (let i = 0; i < rowCount; ++i)
|
|
80
|
+
for (let i = 0; i < rowCount; ++i) {
|
|
84
81
|
for (let j = 0; j < components; ++j)
|
|
85
82
|
umapColumnsData[j][i] = embeddings[i][j];
|
|
83
|
+
}
|
|
86
84
|
|
|
87
|
-
return DG.DataFrame.fromColumns(range.map(i =>
|
|
88
|
-
DG.Column.fromFloat32Array('UMAP' + i.toString(), umapColumnsData[i])
|
|
85
|
+
return DG.DataFrame.fromColumns(range.map((i) =>
|
|
86
|
+
DG.Column.fromFloat32Array('UMAP' + i.toString(), umapColumnsData[i]),
|
|
89
87
|
));
|
|
90
88
|
} // computeUMAP
|
|
91
89
|
|
|
92
90
|
// t-distributed stochastic neighbor embedding (t-SNE)
|
|
93
|
-
export async function computeTSNE(features: DG.ColumnList, components: number,
|
|
94
|
-
learningRate: number, perplexity: number, iterations: number): Promise<DG.DataFrame>
|
|
95
|
-
{
|
|
91
|
+
export async function computeTSNE(features: DG.ColumnList, components: number,
|
|
92
|
+
learningRate: number, perplexity: number, iterations: number): Promise<DG.DataFrame> {
|
|
96
93
|
// check inputs
|
|
97
94
|
checkTSNEinputs(features, components, learningRate, perplexity, iterations);
|
|
98
95
|
|
|
@@ -102,26 +99,27 @@ export async function computeTSNE(features: DG.ColumnList, components: number,
|
|
|
102
99
|
let workerOutput: any;
|
|
103
100
|
|
|
104
101
|
// t-SNE in webworker
|
|
105
|
-
|
|
102
|
+
const promise = new Promise((resolve, _reject) => {
|
|
106
103
|
const worker = new Worker(new URL('workers/tsne-worker.ts', import.meta.url));
|
|
107
|
-
|
|
104
|
+
|
|
108
105
|
worker.postMessage({
|
|
109
|
-
data: data,
|
|
106
|
+
data: data,
|
|
110
107
|
options: {
|
|
111
108
|
learningRate: learningRate,
|
|
112
109
|
perplexity: perplexity,
|
|
113
110
|
components: components,
|
|
114
|
-
iterations: iterations
|
|
115
|
-
|
|
111
|
+
iterations: iterations,
|
|
112
|
+
}});
|
|
116
113
|
|
|
117
114
|
worker.onmessage = function(e) {
|
|
118
115
|
worker.terminate();
|
|
119
|
-
resolve(e.data.embeddings);
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
resolve(e.data.embeddings);
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
|
|
122
120
|
await promise.then(
|
|
123
|
-
result => {
|
|
124
|
-
|
|
121
|
+
(result) => {workerOutput = result;},
|
|
122
|
+
(_error) => {throw new Error('applying t-SNE fails.');},
|
|
125
123
|
);
|
|
126
124
|
|
|
127
125
|
const embeddings = workerOutput as any[];
|
|
@@ -132,54 +130,15 @@ export async function computeTSNE(features: DG.ColumnList, components: number,
|
|
|
132
130
|
// Create output
|
|
133
131
|
|
|
134
132
|
// columns data
|
|
135
|
-
const umapColumnsData = range.map(_ => new Float32Array(rowCount));
|
|
133
|
+
const umapColumnsData = range.map((_) => new Float32Array(rowCount));
|
|
136
134
|
|
|
137
135
|
// perform transponation
|
|
138
|
-
for (let i = 0; i < rowCount; ++i)
|
|
136
|
+
for (let i = 0; i < rowCount; ++i) {
|
|
139
137
|
for (let j = 0; j < components; ++j)
|
|
140
138
|
umapColumnsData[j][i] = embeddings[i][j];
|
|
139
|
+
}
|
|
141
140
|
|
|
142
|
-
return DG.DataFrame.fromColumns(range.map(i =>
|
|
143
|
-
DG.Column.fromFloat32Array('tSNE' + i.toString(), umapColumnsData[i])
|
|
141
|
+
return DG.DataFrame.fromColumns(range.map((i) =>
|
|
142
|
+
DG.Column.fromFloat32Array('tSNE' + i.toString(), umapColumnsData[i]),
|
|
144
143
|
));
|
|
145
144
|
} // computeTSNE
|
|
146
|
-
|
|
147
|
-
// Stochastic proximity embedding (SPE)
|
|
148
|
-
export async function computeSPE(features: DG.ColumnList, dimension: number,
|
|
149
|
-
steps: number, cycles: number, cutoff: number, lambda: number): Promise<DG.DataFrame>
|
|
150
|
-
{
|
|
151
|
-
// check inputs
|
|
152
|
-
checkSPEinputs(features, dimension, steps, cycles, cutoff, lambda);
|
|
153
|
-
|
|
154
|
-
// get row-by-row data
|
|
155
|
-
const data = getRowsOfNumericalColumnns(features);
|
|
156
|
-
|
|
157
|
-
// SPE reducer
|
|
158
|
-
const spe = new DimensionalityReducer(data, 'SPE', VectorMetricsNames.Euclidean, {
|
|
159
|
-
dimension: dimension,
|
|
160
|
-
steps: steps,
|
|
161
|
-
cycles: cycles,
|
|
162
|
-
cutoff: cutoff,
|
|
163
|
-
lambda: lambda
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// compute embeddings
|
|
167
|
-
const embeddings = (await spe.transform(false, false)).embedding;
|
|
168
|
-
|
|
169
|
-
const rowCount = embeddings.length;
|
|
170
|
-
const range = [...Array(dimension).keys()];
|
|
171
|
-
|
|
172
|
-
// Create output
|
|
173
|
-
|
|
174
|
-
// columns data
|
|
175
|
-
const umapColumnsData = range.map(_ => new Float32Array(rowCount));
|
|
176
|
-
|
|
177
|
-
// perform transponation
|
|
178
|
-
for (let i = 0; i < rowCount; ++i)
|
|
179
|
-
for (let j = 0; j < dimension; ++j)
|
|
180
|
-
umapColumnsData[j][i] = embeddings[i][j];
|
|
181
|
-
|
|
182
|
-
return DG.DataFrame.fromColumns(range.map(i =>
|
|
183
|
-
DG.Column.fromFloat32Array('SPE' + i.toString(), umapColumnsData[i])
|
|
184
|
-
));
|
|
185
|
-
} // computeSPE
|
package/src/eda-ui.ts
CHANGED
|
@@ -5,8 +5,8 @@ import * as ui from 'datagrok-api/ui';
|
|
|
5
5
|
import * as DG from 'datagrok-api/dg';
|
|
6
6
|
|
|
7
7
|
// Rename PCA columns
|
|
8
|
-
export function renamePCAcolumns(pcaTable: DG.DataFrame): DG.DataFrame {
|
|
9
|
-
for (const col of pcaTable.columns.toList())
|
|
8
|
+
export function renamePCAcolumns(pcaTable: DG.DataFrame): DG.DataFrame {
|
|
9
|
+
for (const col of pcaTable.columns.toList())
|
|
10
10
|
col.name = 'PCA' + col.name;
|
|
11
11
|
|
|
12
12
|
return pcaTable;
|
|
@@ -19,116 +19,123 @@ export function addPrefixToEachColumnName(prefix: string, columns: DG.ColumnList
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// Predicted vs Reference scatter plot
|
|
22
|
-
export function predictedVersusReferenceScatterPlot(
|
|
22
|
+
export function predictedVersusReferenceScatterPlot(
|
|
23
|
+
samplesNames: DG.Column, reference: DG.Column, prediction: DG.Column,
|
|
24
|
+
): DG.Viewer {
|
|
23
25
|
prediction.name = reference.name + '(predicted)';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
|
|
27
|
+
const dfReferencePrediction = DG.DataFrame.fromColumns([samplesNames, reference, prediction]);
|
|
26
28
|
dfReferencePrediction.name = 'Reference vs. Predicted';
|
|
27
|
-
|
|
28
|
-
return DG.Viewer.scatterPlot(dfReferencePrediction,
|
|
29
|
-
{
|
|
29
|
+
|
|
30
|
+
return DG.Viewer.scatterPlot(dfReferencePrediction,
|
|
31
|
+
{title: dfReferencePrediction.name,
|
|
30
32
|
x: reference.name,
|
|
31
33
|
y: prediction.name,
|
|
32
34
|
showRegressionLine: true,
|
|
33
35
|
markerType: 'circle',
|
|
34
|
-
labels: samplesNames.name
|
|
35
|
-
|
|
36
|
+
labels: samplesNames.name,
|
|
37
|
+
});
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
// Regression Coefficients Bar Chart
|
|
39
|
-
export function regressionCoefficientsBarChart(features: DG.ColumnList, regressionCoeffs: DG.Column): DG.Viewer {
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
export function regressionCoefficientsBarChart(features: DG.ColumnList, regressionCoeffs: DG.Column): DG.Viewer {
|
|
42
|
+
regressionCoeffs.name = 'regression coefficient';
|
|
43
|
+
|
|
44
|
+
const namesOfPredictors = [];
|
|
42
45
|
for (const col of features)
|
|
43
|
-
namesOfPredictors.push(col.name);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
namesOfPredictors.push(col.name);
|
|
47
|
+
|
|
48
|
+
const predictorNamesColumn = DG.Column.fromStrings('feature', namesOfPredictors);
|
|
49
|
+
|
|
50
|
+
const dfRegrCoefs = DG.DataFrame.fromColumns([predictorNamesColumn, regressionCoeffs]);
|
|
48
51
|
dfRegrCoefs.name = 'Regression Coefficients';
|
|
49
52
|
|
|
50
|
-
return DG.Viewer.barChart(dfRegrCoefs,
|
|
51
|
-
{title: dfRegrCoefs.name, split: 'feature',
|
|
52
|
-
|
|
53
|
+
return DG.Viewer.barChart(dfRegrCoefs,
|
|
54
|
+
{title: dfRegrCoefs.name, split: 'feature',
|
|
55
|
+
value: 'regression coefficient', valueAggrType: 'avg'});
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
// Scores Scatter Plot
|
|
56
|
-
export function scoresScatterPlot(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
export function scoresScatterPlot(
|
|
60
|
+
samplesNames: DG.Column, xScores: Array<DG.Column>, yScores: Array<DG.Column>,
|
|
61
|
+
): DG.Viewer {
|
|
62
|
+
const scoresColumns = [samplesNames];
|
|
59
63
|
|
|
60
64
|
for (let i = 0; i < xScores.length; i++) {
|
|
61
65
|
xScores[i].name = `x.score.t${i+1}`;
|
|
62
66
|
scoresColumns.push(xScores[i]);
|
|
63
|
-
}
|
|
64
|
-
|
|
67
|
+
}
|
|
68
|
+
|
|
65
69
|
for (let i = 0; i < yScores.length; i++) {
|
|
66
70
|
yScores[i].name = `y.score.u${i+1}`;
|
|
67
71
|
scoresColumns.push(yScores[i]);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const scores = DG.DataFrame.fromColumns(scoresColumns);
|
|
71
75
|
scores.name = 'Scores';
|
|
72
76
|
//grok.shell.addTableView(scores);
|
|
73
77
|
|
|
74
78
|
const index = xScores.length > 1 ? 1 : 0;
|
|
75
|
-
|
|
76
|
-
return DG.Viewer.scatterPlot(scores,
|
|
77
|
-
{
|
|
79
|
+
|
|
80
|
+
return DG.Viewer.scatterPlot(scores,
|
|
81
|
+
{title: scores.name,
|
|
78
82
|
x: xScores[0].name,
|
|
79
|
-
y: xScores[index].name,
|
|
83
|
+
y: xScores[index].name,
|
|
80
84
|
markerType: 'circle',
|
|
81
|
-
labels: samplesNames.name
|
|
82
|
-
|
|
85
|
+
labels: samplesNames.name,
|
|
86
|
+
});
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
// Loading Scatter Plot
|
|
86
90
|
export function loadingScatterPlot(features: DG.ColumnList, xLoadings: Array<DG.Column>): DG.Viewer {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
for (
|
|
91
|
+
const loadingCols = [];
|
|
92
|
+
|
|
93
|
+
const loadingLabels = [];
|
|
94
|
+
for (const col of features)
|
|
91
95
|
loadingLabels.push(col.name);
|
|
92
|
-
|
|
93
|
-
loadingCols.push(DG.Column.fromStrings('labels', loadingLabels));
|
|
94
|
-
|
|
96
|
+
|
|
97
|
+
loadingCols.push(DG.Column.fromStrings('labels', loadingLabels));
|
|
98
|
+
|
|
95
99
|
for (let i = 0; i < xLoadings.length; i++) {
|
|
96
100
|
xLoadings[i].name = `x.loading.p${i+1}`;
|
|
97
101
|
loadingCols.push(xLoadings[i]);
|
|
98
102
|
}
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
|
|
104
|
+
const dfLoadings = DG.DataFrame.fromColumns(loadingCols);
|
|
101
105
|
dfLoadings.name = 'Loadings';
|
|
102
|
-
|
|
103
|
-
return DG.Viewer.scatterPlot(dfLoadings,
|
|
104
|
-
{
|
|
106
|
+
|
|
107
|
+
return DG.Viewer.scatterPlot(dfLoadings,
|
|
108
|
+
{title: dfLoadings.name,
|
|
105
109
|
x: xLoadings[0].name,
|
|
106
|
-
y: xLoadings[xLoadings.length - 1].name,
|
|
110
|
+
y: xLoadings[xLoadings.length - 1].name,
|
|
107
111
|
markerType: 'circle',
|
|
108
|
-
labels: 'labels'
|
|
109
|
-
|
|
112
|
+
labels: 'labels',
|
|
113
|
+
});
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
// Add PLS visualization
|
|
113
|
-
export function addPLSvisualization(
|
|
114
|
-
|
|
117
|
+
export function addPLSvisualization(
|
|
118
|
+
table: DG.DataFrame, samplesNames: DG.Column, features: DG.ColumnList, predict: DG.Column, plsOutput: any,
|
|
119
|
+
): void {
|
|
115
120
|
const view = grok.shell.getTableView(table.name);
|
|
116
|
-
|
|
121
|
+
|
|
117
122
|
// 1. Predicted vs Reference scatter plot
|
|
118
123
|
view.addViewer(predictedVersusReferenceScatterPlot(samplesNames, predict, plsOutput[0]));
|
|
119
|
-
|
|
124
|
+
|
|
120
125
|
// 2. Regression Coefficients Bar Chart
|
|
121
|
-
view.addViewer(regressionCoefficientsBarChart(features, plsOutput[1]));
|
|
122
|
-
|
|
126
|
+
view.addViewer(regressionCoefficientsBarChart(features, plsOutput[1]));
|
|
127
|
+
|
|
123
128
|
// 3. Loading Scatter Plot
|
|
124
|
-
view.addViewer(loadingScatterPlot(features, plsOutput[4]));
|
|
129
|
+
view.addViewer(loadingScatterPlot(features, plsOutput[4]));
|
|
125
130
|
|
|
126
131
|
// 4. Scores Scatter Plot
|
|
127
132
|
view.addViewer(scoresScatterPlot(samplesNames, plsOutput[2], plsOutput[3]));
|
|
128
133
|
}
|
|
129
134
|
|
|
130
135
|
// Add one-way ANOVA results
|
|
131
|
-
export function addOneWayAnovaVizualization(
|
|
136
|
+
export function addOneWayAnovaVizualization(
|
|
137
|
+
table: DG.DataFrame, factors: DG.Column, values: DG.Column, anova: DG.DataFrame,
|
|
138
|
+
) {
|
|
132
139
|
const view = grok.shell.getTableView(table.name);
|
|
133
140
|
view.addViewer(DG.Viewer.boxPlot(DG.DataFrame.fromColumns([factors, values])));
|
|
134
141
|
view.addViewer(DG.Viewer.grid(anova));
|
package/src/package-test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as DG from
|
|
1
|
+
import * as DG from 'datagrok-api/dg';
|
|
2
2
|
import {runTests, tests, TestContext} from '@datagrok-libraries/utils/src/test';
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export const _package = new DG.Package();
|
|
5
5
|
export {tests};
|
|
6
6
|
|
|
7
7
|
//name: test
|