@datagrok/eda 1.0.3
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/README.md +3 -0
- package/detectors.js +9 -0
- package/dist/111.js +2 -0
- package/dist/146.js +2 -0
- package/dist/155.js +2 -0
- package/dist/355.js +2 -0
- package/dist/584.js +2 -0
- package/dist/604.js +2 -0
- package/dist/632.js +2 -0
- package/dist/645.js +2 -0
- package/dist/93.js +2 -0
- package/dist/d711f70338306e5bddc4.wasm +0 -0
- package/dist/package-test.js +2 -0
- package/dist/package.js +2 -0
- package/package.json +49 -0
- package/package.png +0 -0
- package/scripts/command.txt +1 -0
- package/scripts/exportForTS.py +862 -0
- package/scripts/exportForTSConstants.py +93 -0
- package/scripts/func.json +1 -0
- package/scripts/module.json +11 -0
- package/src/EDAtools.ts +46 -0
- package/src/EDAui.ts +118 -0
- package/src/dataGenerators.ts +74 -0
- package/src/demos.ts +38 -0
- package/src/package-test.ts +12 -0
- package/src/package.ts +248 -0
- package/src/svm.ts +485 -0
- package/src/utils.ts +51 -0
- package/tsconfig.json +71 -0
- package/wasm/EDA.js +443 -0
- package/wasm/EDA.wasm +0 -0
- package/wasm/EDAAPI.js +131 -0
- package/wasm/EDAForWebWorker.js +21 -0
- package/wasm/PCA/PCA.cpp +151 -0
- package/wasm/PCA/PCA.h +48 -0
- package/wasm/PLS/PLS.h +64 -0
- package/wasm/PLS/pls.cpp +393 -0
- package/wasm/callWasm.js +475 -0
- package/wasm/callWasmForWebWorker.js +706 -0
- package/wasm/dataGenerators.h +169 -0
- package/wasm/dataMining.h +116 -0
- package/wasm/pcaExport.cpp +64 -0
- package/wasm/plsExport.cpp +75 -0
- package/wasm/svm.h +608 -0
- package/wasm/svmApi.cpp +323 -0
- package/wasm/workers/errorWorker.js +13 -0
- package/wasm/workers/generateDatasetWorker.js +13 -0
- package/wasm/workers/normalizeDatasetWorker.js +13 -0
- package/wasm/workers/partialLeastSquareRegressionWorker.js +13 -0
- package/wasm/workers/predictByLSSVMWorker.js +13 -0
- package/wasm/workers/principalComponentAnalysisWorker.js +13 -0
- package/wasm/workers/trainAndAnalyzeLSSVMWorker.js +13 -0
- package/wasm/workers/trainLSSVMWorker.js +13 -0
- package/webpack.config.js +37 -0
package/src/package.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/* Do not change these import lines to match external modules in webpack configuration */
|
|
2
|
+
import * as grok from 'datagrok-api/grok';
|
|
3
|
+
import * as ui from 'datagrok-api/ui';
|
|
4
|
+
import * as DG from 'datagrok-api/dg';
|
|
5
|
+
|
|
6
|
+
import {DemoScript} from '@datagrok-libraries/tutorials/src/demo-script';
|
|
7
|
+
|
|
8
|
+
import {_initEDAAPI} from '../wasm/EDAAPI';
|
|
9
|
+
import {computePCA, computePLS} from './EDAtools';
|
|
10
|
+
import {renamePCAcolumns, addPLSvisualization} from './EDAui';
|
|
11
|
+
import {demoPLS} from './demos';
|
|
12
|
+
import {carsDataframe, testDataForBinaryClassification} from './dataGenerators';
|
|
13
|
+
import {LINEAR, RBF, POLYNOMIAL, SIGMOID,
|
|
14
|
+
getTrainedModel, getPrediction, showTrainReport, getPackedModel} from './svm';
|
|
15
|
+
|
|
16
|
+
export const _package = new DG.Package();
|
|
17
|
+
|
|
18
|
+
//name: info
|
|
19
|
+
export function info() {
|
|
20
|
+
grok.shell.info(_package.webRoot);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//tags: init
|
|
24
|
+
export async function init(): Promise<void> {
|
|
25
|
+
await _initEDAAPI();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//top-menu: Tools | Data Science | PCA
|
|
29
|
+
//name: PCA
|
|
30
|
+
//description: Principal component analysis (PCA).
|
|
31
|
+
//input: dataframe table
|
|
32
|
+
//input: column_list features
|
|
33
|
+
//input: int components = 2
|
|
34
|
+
//input: bool center = true
|
|
35
|
+
//input: bool scale = true
|
|
36
|
+
//output: dataframe result {action:join(table)}
|
|
37
|
+
export async function PCA(table: DG.DataFrame, features: DG.ColumnList, components: number,
|
|
38
|
+
center: boolean, scale: boolean): Promise<DG.DataFrame>
|
|
39
|
+
{
|
|
40
|
+
return renamePCAcolumns(await computePCA(table, features, components, center, scale));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//top-menu: Tools | Data Science | PLS
|
|
44
|
+
//name: PLS
|
|
45
|
+
//description: Partial least square regression (PLS).
|
|
46
|
+
//input: dataframe table
|
|
47
|
+
//input: column_list features
|
|
48
|
+
//input: column predict
|
|
49
|
+
//input: int components = 3
|
|
50
|
+
export async function PLS(table: DG.DataFrame, features: DG.ColumnList, predict: DG.Column, components: number): Promise<void> {
|
|
51
|
+
const plsResults = await computePLS(table, features, predict, components);
|
|
52
|
+
addPLSvisualization(table, features, predict, plsResults);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//name: MVA demo
|
|
56
|
+
//description: Multivariate analysis (PLS) demo.
|
|
57
|
+
//meta.demoPath: Data analysis | Multivariate analysis
|
|
58
|
+
export async function demoScript(): Promise<any> {
|
|
59
|
+
const demoScript = new DemoScript('Multivariate analysis',
|
|
60
|
+
'Provides partial least sqaure regression analysis of the given data.');
|
|
61
|
+
|
|
62
|
+
const cars = carsDataframe();
|
|
63
|
+
|
|
64
|
+
const components = 3;
|
|
65
|
+
const predict = cars.columns.byName('price');
|
|
66
|
+
const features = cars.columns.remove('price').remove('model');
|
|
67
|
+
const plsOutput = await computePLS(cars, features, predict, components);
|
|
68
|
+
|
|
69
|
+
const sourceCars = carsDataframe();
|
|
70
|
+
grok.shell.addTableView(sourceCars);
|
|
71
|
+
sourceCars.name = 'Cars';
|
|
72
|
+
let view = grok.shell.getTableView(sourceCars.name);
|
|
73
|
+
|
|
74
|
+
await demoScript
|
|
75
|
+
.step('Run', async () => {}, {description: 'Test dataframe is loaded, and multivariate analysis is performed.', delay: 0})
|
|
76
|
+
.step('Study', async () => {addPLSvisualization(sourceCars, features, predict, plsOutput)}, {description: 'Investigate results.', delay: 4000})
|
|
77
|
+
.step('Try', async () => {
|
|
78
|
+
const params = { items: 10000, features: 100, components: 3};
|
|
79
|
+
const itemsProp = DG.Property.js('items', DG.TYPE.INT);
|
|
80
|
+
const featuresProp = DG.Property.js('features', DG.TYPE.INT);
|
|
81
|
+
const componentsProp = DG.Property.js('components', DG.TYPE.INT);
|
|
82
|
+
ui.dialog({title:'Set'})
|
|
83
|
+
.add(ui.input.form(params, [itemsProp, featuresProp, componentsProp]))
|
|
84
|
+
.addButton('Run', async () => await demoPLS(params.items, params.features, params.components))
|
|
85
|
+
.show();
|
|
86
|
+
}, {description: 'Random walk test dataframe of the given size is generated, and its multivariate analysis is performed.'})
|
|
87
|
+
.start();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//name: Generate linear separable dataset
|
|
91
|
+
//description: Generates linear separble dataset for testing binary classificators.
|
|
92
|
+
//input: string name = 'Data' {caption: name; category: Dataset}
|
|
93
|
+
//input: int samplesCount = 1000 {caption: samples; category: Size}
|
|
94
|
+
//input: int featuresCount = 2 {caption: features; category: Size}
|
|
95
|
+
//input: double min = -39 {caption: min; category: Range}
|
|
96
|
+
//input: double max = 173 {caption: max; category: Range}
|
|
97
|
+
//input: double violatorsPercentage = 5 {caption: violators; units: %; category: Dataset}
|
|
98
|
+
//output: dataframe df
|
|
99
|
+
export async function testDataLinearSeparable(name: string, samplesCount: number, featuresCount: number,
|
|
100
|
+
min: number, max: number, violatorsPercentage: number): Promise<DG.DataFrame>
|
|
101
|
+
{
|
|
102
|
+
return await testDataForBinaryClassification(LINEAR, [0, 0], name, samplesCount, featuresCount,
|
|
103
|
+
min, max, violatorsPercentage);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//name: Generate linear non-separable dataset
|
|
107
|
+
//description: Generates linear non-separble dataset for testing binary classificators.
|
|
108
|
+
//input: string name = 'Data' {caption: name; category: Dataset}
|
|
109
|
+
//input: double sigma = 90 {caption: sigma; category: Hyperparameters} [RBF-kernel paramater]
|
|
110
|
+
//input: int samplesCount = 1000 {caption: samples; category: Size}
|
|
111
|
+
//input: int featuresCount = 2 {caption: features; category: Size}
|
|
112
|
+
//input: double min = -39 {caption: min; category: Range}
|
|
113
|
+
//input: double max = 173 {caption: max; category: Range}
|
|
114
|
+
//input: double violatorsPercentage = 5 {caption: violators; units: %; category: Dataset}
|
|
115
|
+
//output: dataframe df
|
|
116
|
+
export async function testDataLinearNonSeparable(name: string, sigma: number, samplesCount: number,
|
|
117
|
+
featuresCount: number, min: number, max: number, violatorsPercentage: number): Promise<DG.DataFrame>
|
|
118
|
+
{
|
|
119
|
+
return await testDataForBinaryClassification(RBF, [sigma, 0], name, samplesCount, featuresCount,
|
|
120
|
+
min, max, violatorsPercentage);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//name: trainLinearKernelSVM
|
|
124
|
+
//meta.mlname: linear kernel LS-SVM
|
|
125
|
+
//meta.mlrole: train
|
|
126
|
+
//input: dataframe df
|
|
127
|
+
//input: string predict_column
|
|
128
|
+
//input: double gamma = 1.0 {category: Hyperparameters}
|
|
129
|
+
//input: bool toShowReport = false {caption: to show report; category: Report}
|
|
130
|
+
//output: dynamic model
|
|
131
|
+
export async function trainLinearKernelSVM(df: DG.DataFrame, predict_column: string,
|
|
132
|
+
gamma: number, toShowReport: boolean): Promise<any>
|
|
133
|
+
{
|
|
134
|
+
const trainedModel = await getTrainedModel({gamma: gamma, kernel: LINEAR}, df, predict_column);
|
|
135
|
+
|
|
136
|
+
if (toShowReport)
|
|
137
|
+
showTrainReport(df, trainedModel);
|
|
138
|
+
|
|
139
|
+
return getPackedModel(trainedModel);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
//name: applyLinearKernelSVM
|
|
143
|
+
//meta.mlname: linear kernel LS-SVM
|
|
144
|
+
//meta.mlrole: apply
|
|
145
|
+
//input: dataframe df
|
|
146
|
+
//input: dynamic model
|
|
147
|
+
//output: dataframe table
|
|
148
|
+
export async function applyLinearKernelSVM(df: DG.DataFrame, model: any): Promise<DG.DataFrame> {
|
|
149
|
+
return await getPrediction(df, model);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//name: trainRBFkernelSVM
|
|
153
|
+
//meta.mlname: RBF-kernel LS-SVM
|
|
154
|
+
//meta.mlrole: train
|
|
155
|
+
//input: dataframe df
|
|
156
|
+
//input: string predict_column
|
|
157
|
+
//input: double gamma = 1.0 {category: Hyperparameters}
|
|
158
|
+
//input: double sigma = 1.5 {category: Hyperparameters}
|
|
159
|
+
//input: bool toShowReport = false {caption: to show report; category: Report}
|
|
160
|
+
//output: dynamic model
|
|
161
|
+
export async function trainRBFkernelSVM(df: DG.DataFrame, predict_column: string,
|
|
162
|
+
gamma: number, sigma: number, toShowReport: boolean): Promise<any>
|
|
163
|
+
{
|
|
164
|
+
const trainedModel = await getTrainedModel(
|
|
165
|
+
{gamma: gamma, kernel: RBF, sigma: sigma},
|
|
166
|
+
df, predict_column);
|
|
167
|
+
|
|
168
|
+
if (toShowReport)
|
|
169
|
+
showTrainReport(df, trainedModel);
|
|
170
|
+
|
|
171
|
+
return getPackedModel(trainedModel);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//name: applyRBFkernelSVM
|
|
175
|
+
//meta.mlname: RBF-kernel LS-SVM
|
|
176
|
+
//meta.mlrole: apply
|
|
177
|
+
//input: dataframe df
|
|
178
|
+
//input: dynamic model
|
|
179
|
+
//output: dataframe table
|
|
180
|
+
export async function applyRBFkernelSVM(df: DG.DataFrame, model: any): Promise<DG.DataFrame> {
|
|
181
|
+
return await getPrediction(df, model);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//name: trainPolynomialKernelSVM
|
|
185
|
+
//meta.mlname: polynomial kernel LS-SVM
|
|
186
|
+
//meta.mlrole: train
|
|
187
|
+
//input: dataframe df
|
|
188
|
+
//input: string predict_column
|
|
189
|
+
//input: double gamma = 1.0 {category: Hyperparameters}
|
|
190
|
+
//input: double c = 1 {category: Hyperparameters}
|
|
191
|
+
//input: double d = 2 {category: Hyperparameters}
|
|
192
|
+
//input: bool toShowReport = false {caption: to show report; category: Report}
|
|
193
|
+
//output: dynamic model
|
|
194
|
+
export async function trainPolynomialKernelSVM(df: DG.DataFrame, predict_column: string,
|
|
195
|
+
gamma: number, c: number, d: number, toShowReport: boolean): Promise<any>
|
|
196
|
+
{
|
|
197
|
+
const trainedModel = await getTrainedModel(
|
|
198
|
+
{gamma: gamma, kernel: POLYNOMIAL, cParam: c, dParam: d},
|
|
199
|
+
df, predict_column);
|
|
200
|
+
|
|
201
|
+
if (toShowReport)
|
|
202
|
+
showTrainReport(df, trainedModel);
|
|
203
|
+
|
|
204
|
+
return getPackedModel(trainedModel);
|
|
205
|
+
} // trainPolynomialKernelSVM
|
|
206
|
+
|
|
207
|
+
//name: applyPolynomialKernelSVM
|
|
208
|
+
//meta.mlname: polynomial kernel LS-SVM
|
|
209
|
+
//meta.mlrole: apply
|
|
210
|
+
//input: dataframe df
|
|
211
|
+
//input: dynamic model
|
|
212
|
+
//output: dataframe table
|
|
213
|
+
export async function applyPolynomialKernelSVM(df: DG.DataFrame, model: any): Promise<DG.DataFrame> {
|
|
214
|
+
return await getPrediction(df, model);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//name: trainSigmoidKernelSVM
|
|
218
|
+
//meta.mlname: sigmoid kernel LS-SVM
|
|
219
|
+
//meta.mlrole: train
|
|
220
|
+
//input: dataframe df
|
|
221
|
+
//input: string predict_column
|
|
222
|
+
//input: double gamma = 1.0 {category: Hyperparameters}
|
|
223
|
+
//input: double kappa = 1 {category: Hyperparameters}
|
|
224
|
+
//input: double theta = 1 {category: Hyperparameters}
|
|
225
|
+
//input: bool toShowReport = false {caption: to show report; category: Report}
|
|
226
|
+
//output: dynamic model
|
|
227
|
+
export async function trainSigmoidKernelSVM(df: DG.DataFrame, predict_column: string,
|
|
228
|
+
gamma: number, kappa: number, theta: number, toShowReport: boolean): Promise<any>
|
|
229
|
+
{
|
|
230
|
+
const trainedModel = await getTrainedModel(
|
|
231
|
+
{gamma: gamma, kernel: SIGMOID, kappa: kappa, theta: theta},
|
|
232
|
+
df, predict_column);
|
|
233
|
+
|
|
234
|
+
if (toShowReport)
|
|
235
|
+
showTrainReport(df, trainedModel);
|
|
236
|
+
|
|
237
|
+
return getPackedModel(trainedModel);
|
|
238
|
+
} // trainSigmoidKernelSVM
|
|
239
|
+
|
|
240
|
+
//name: applySigmoidKernelSVM
|
|
241
|
+
//meta.mlname: sigmoid kernel LS-SVM
|
|
242
|
+
//meta.mlrole: apply
|
|
243
|
+
//input: dataframe df
|
|
244
|
+
//input: dynamic model
|
|
245
|
+
//output: dataframe table
|
|
246
|
+
export async function applySigmoidKernelSVM(df: DG.DataFrame, model: any): Promise<DG.DataFrame> {
|
|
247
|
+
return await getPrediction(df, model);
|
|
248
|
+
}
|