linreg-core 0.8.0 → 0.8.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.
- package/linreg_core.d.ts +359 -0
- package/linreg_core.js +590 -0
- package/linreg_core_bg.wasm +0 -0
- package/package.json +4 -4
package/linreg_core.d.ts
CHANGED
|
@@ -767,6 +767,122 @@ export function ols_regression(y_json: string, x_vars_json: string, variable_nam
|
|
|
767
767
|
*/
|
|
768
768
|
export function parse_csv(content: string): string;
|
|
769
769
|
|
|
770
|
+
/**
|
|
771
|
+
* Computes permutation importance for Elastic Net regression.
|
|
772
|
+
*
|
|
773
|
+
* # Arguments
|
|
774
|
+
*
|
|
775
|
+
* * `y_json` - JSON array of response values
|
|
776
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
777
|
+
* * `fit_json` - JSON string of Elastic Net fit result
|
|
778
|
+
* * `n_permutations` - Number of permutation iterations
|
|
779
|
+
* * `seed` - Random seed (use 0 for no seed)
|
|
780
|
+
* * `compute_intervals` - Whether to compute confidence intervals
|
|
781
|
+
* * `interval_confidence` - Confidence level for intervals (0-1)
|
|
782
|
+
*
|
|
783
|
+
* # Returns
|
|
784
|
+
*
|
|
785
|
+
* JSON string of [`PermutationImportanceOutput`]
|
|
786
|
+
*
|
|
787
|
+
* # Example
|
|
788
|
+
*
|
|
789
|
+
* ```javascript
|
|
790
|
+
* const y = [2.5, 3.7, 4.2, 5.1, 6.3];
|
|
791
|
+
* const x = [[1,2,3,4,5], [2,4,5,4,3]];
|
|
792
|
+
* const fit = JSON.parse(elastic_net_regression(...));
|
|
793
|
+
*
|
|
794
|
+
* const result = JSON.parse(permutation_importance_elastic_net(
|
|
795
|
+
* JSON.stringify(y),
|
|
796
|
+
* JSON.stringify(x),
|
|
797
|
+
* JSON.stringify(fit),
|
|
798
|
+
* 50, // n_permutations
|
|
799
|
+
* 42, // seed
|
|
800
|
+
* true, // compute_intervals
|
|
801
|
+
* 0.95 // interval_confidence
|
|
802
|
+
* ));
|
|
803
|
+
* console.log(result.importance);
|
|
804
|
+
* ```
|
|
805
|
+
*/
|
|
806
|
+
export function permutation_importance_elastic_net(y_json: string, x_json: string, fit_json: string, n_permutations: number, seed: bigint, compute_intervals: boolean, interval_confidence: number): string;
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Computes permutation importance for Lasso regression.
|
|
810
|
+
*
|
|
811
|
+
* # Arguments
|
|
812
|
+
*
|
|
813
|
+
* * `y_json` - JSON array of response values
|
|
814
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
815
|
+
* * `fit_json` - JSON string of Lasso fit result
|
|
816
|
+
* * `n_permutations` - Number of permutation iterations
|
|
817
|
+
* * `seed` - Random seed (use 0 for no seed)
|
|
818
|
+
* * `compute_intervals` - Whether to compute confidence intervals
|
|
819
|
+
* * `interval_confidence` - Confidence level for intervals (0-1)
|
|
820
|
+
*
|
|
821
|
+
* # Returns
|
|
822
|
+
*
|
|
823
|
+
* JSON string of [`PermutationImportanceOutput`]
|
|
824
|
+
*
|
|
825
|
+
* # Example
|
|
826
|
+
*
|
|
827
|
+
* ```javascript
|
|
828
|
+
* const y = [2.5, 3.7, 4.2, 5.1, 6.3];
|
|
829
|
+
* const x = [[1,2,3,4,5], [2,4,5,4,3]];
|
|
830
|
+
* const fit = JSON.parse(lasso_regression(...));
|
|
831
|
+
*
|
|
832
|
+
* const result = JSON.parse(permutation_importance_lasso(
|
|
833
|
+
* JSON.stringify(y),
|
|
834
|
+
* JSON.stringify(x),
|
|
835
|
+
* JSON.stringify(fit),
|
|
836
|
+
* 50, // n_permutations
|
|
837
|
+
* 42, // seed
|
|
838
|
+
* true, // compute_intervals
|
|
839
|
+
* 0.95 // interval_confidence
|
|
840
|
+
* ));
|
|
841
|
+
* console.log(result.importance);
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
export function permutation_importance_lasso(y_json: string, x_json: string, fit_json: string, n_permutations: number, seed: bigint, compute_intervals: boolean, interval_confidence: number): string;
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Computes permutation importance for LOESS regression.
|
|
848
|
+
*
|
|
849
|
+
* # Arguments
|
|
850
|
+
*
|
|
851
|
+
* * `y_json` - JSON array of response values
|
|
852
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
853
|
+
* * `span` - Span parameter used in original fit
|
|
854
|
+
* * `degree` - Degree of polynomial used in original fit
|
|
855
|
+
* * `n_permutations` - Number of permutation iterations
|
|
856
|
+
* * `seed` - Random seed (use 0 for no seed)
|
|
857
|
+
*
|
|
858
|
+
* # Returns
|
|
859
|
+
*
|
|
860
|
+
* JSON string of [`PermutationImportanceOutput`]
|
|
861
|
+
*
|
|
862
|
+
* # Note
|
|
863
|
+
*
|
|
864
|
+
* This is computationally expensive as it re-fits the LOESS model
|
|
865
|
+
* for each permutation of each feature.
|
|
866
|
+
*
|
|
867
|
+
* # Example
|
|
868
|
+
*
|
|
869
|
+
* ```javascript
|
|
870
|
+
* const y = [2.5, 3.7, 4.2, 5.1, 6.3];
|
|
871
|
+
* const x = [[1,2,3,4,5]];
|
|
872
|
+
*
|
|
873
|
+
* const result = JSON.parse(permutation_importance_loess(
|
|
874
|
+
* JSON.stringify(y),
|
|
875
|
+
* JSON.stringify(x),
|
|
876
|
+
* 0.75, // span
|
|
877
|
+
* 1, // degree
|
|
878
|
+
* 20, // n_permutations (fewer for LOESS since it's slow)
|
|
879
|
+
* 42 // seed
|
|
880
|
+
* ));
|
|
881
|
+
* console.log(result.importance);
|
|
882
|
+
* ```
|
|
883
|
+
*/
|
|
884
|
+
export function permutation_importance_loess(y_json: string, x_json: string, span: number, degree: number, n_permutations: number, seed: bigint): string;
|
|
885
|
+
|
|
770
886
|
/**
|
|
771
887
|
* Computes permutation importance for OLS regression.
|
|
772
888
|
*
|
|
@@ -801,6 +917,44 @@ export function parse_csv(content: string): string;
|
|
|
801
917
|
*/
|
|
802
918
|
export function permutation_importance_ols(y_json: string, x_json: string, fit_json: string, n_permutations: number, seed: bigint): string;
|
|
803
919
|
|
|
920
|
+
/**
|
|
921
|
+
* Computes permutation importance for Ridge regression.
|
|
922
|
+
*
|
|
923
|
+
* # Arguments
|
|
924
|
+
*
|
|
925
|
+
* * `y_json` - JSON array of response values
|
|
926
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
927
|
+
* * `fit_json` - JSON string of Ridge fit result
|
|
928
|
+
* * `n_permutations` - Number of permutation iterations
|
|
929
|
+
* * `seed` - Random seed (use 0 for no seed)
|
|
930
|
+
* * `compute_intervals` - Whether to compute confidence intervals
|
|
931
|
+
* * `interval_confidence` - Confidence level for intervals (0-1)
|
|
932
|
+
*
|
|
933
|
+
* # Returns
|
|
934
|
+
*
|
|
935
|
+
* JSON string of [`PermutationImportanceOutput`]
|
|
936
|
+
*
|
|
937
|
+
* # Example
|
|
938
|
+
*
|
|
939
|
+
* ```javascript
|
|
940
|
+
* const y = [2.5, 3.7, 4.2, 5.1, 6.3];
|
|
941
|
+
* const x = [[1,2,3,4,5], [2,4,5,4,3]];
|
|
942
|
+
* const fit = JSON.parse(ridge_regression(...));
|
|
943
|
+
*
|
|
944
|
+
* const result = JSON.parse(permutation_importance_ridge(
|
|
945
|
+
* JSON.stringify(y),
|
|
946
|
+
* JSON.stringify(x),
|
|
947
|
+
* JSON.stringify(fit),
|
|
948
|
+
* 50, // n_permutations
|
|
949
|
+
* 42, // seed
|
|
950
|
+
* true, // compute_intervals
|
|
951
|
+
* 0.95 // interval_confidence
|
|
952
|
+
* ));
|
|
953
|
+
* console.log(result.importance);
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
export function permutation_importance_ridge(y_json: string, x_json: string, fit_json: string, n_permutations: number, seed: bigint, compute_intervals: boolean, interval_confidence: number): string;
|
|
957
|
+
|
|
804
958
|
/**
|
|
805
959
|
* Fit polynomial Elastic Net regression via WASM.
|
|
806
960
|
*
|
|
@@ -1102,6 +1256,56 @@ export function ridge_regression(y_json: string, x_vars_json: string, _variable_
|
|
|
1102
1256
|
*/
|
|
1103
1257
|
export function serialize_model(model_json: string, model_type: string, name?: string | null): string;
|
|
1104
1258
|
|
|
1259
|
+
/**
|
|
1260
|
+
* Computes SHAP (SHapley Additive exPlanations) values for Elastic Net regression.
|
|
1261
|
+
*
|
|
1262
|
+
* # Arguments
|
|
1263
|
+
*
|
|
1264
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
1265
|
+
* * `fit_json` - JSON string of Elastic Net fit result
|
|
1266
|
+
*
|
|
1267
|
+
* # Returns
|
|
1268
|
+
*
|
|
1269
|
+
* JSON string of [`ShapOutput`]
|
|
1270
|
+
*
|
|
1271
|
+
* # Example
|
|
1272
|
+
*
|
|
1273
|
+
* ```javascript
|
|
1274
|
+
* const fit = JSON.parse(elastic_net_regression(...));
|
|
1275
|
+
* const result = JSON.parse(shap_values_elastic_net(
|
|
1276
|
+
* JSON.stringify([[1,2,3], [2,4,6]]),
|
|
1277
|
+
* JSON.stringify(fit)
|
|
1278
|
+
* ));
|
|
1279
|
+
* console.log(result.mean_abs_shap);
|
|
1280
|
+
* ```
|
|
1281
|
+
*/
|
|
1282
|
+
export function shap_values_elastic_net(x_json: string, fit_json: string): string;
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Computes SHAP (SHapley Additive exPlanations) values for Lasso regression.
|
|
1286
|
+
*
|
|
1287
|
+
* # Arguments
|
|
1288
|
+
*
|
|
1289
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
1290
|
+
* * `fit_json` - JSON string of Lasso fit result
|
|
1291
|
+
*
|
|
1292
|
+
* # Returns
|
|
1293
|
+
*
|
|
1294
|
+
* JSON string of [`ShapOutput`]
|
|
1295
|
+
*
|
|
1296
|
+
* # Example
|
|
1297
|
+
*
|
|
1298
|
+
* ```javascript
|
|
1299
|
+
* const fit = JSON.parse(lasso_regression(...));
|
|
1300
|
+
* const result = JSON.parse(shap_values_lasso(
|
|
1301
|
+
* JSON.stringify([[1,2,3], [2,4,6]]),
|
|
1302
|
+
* JSON.stringify(fit)
|
|
1303
|
+
* ));
|
|
1304
|
+
* console.log(result.mean_abs_shap);
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
1307
|
+
export function shap_values_lasso(x_json: string, fit_json: string): string;
|
|
1308
|
+
|
|
1105
1309
|
/**
|
|
1106
1310
|
* Computes SHAP (SHapley Additive exPlanations) values for linear models.
|
|
1107
1311
|
*
|
|
@@ -1129,6 +1333,56 @@ export function serialize_model(model_json: string, model_type: string, name?: s
|
|
|
1129
1333
|
*/
|
|
1130
1334
|
export function shap_values_linear(x_json: string, coefficients_json: string, variable_names_json: string): string;
|
|
1131
1335
|
|
|
1336
|
+
/**
|
|
1337
|
+
* Computes SHAP (SHapley Additive exPlanations) values for polynomial regression.
|
|
1338
|
+
*
|
|
1339
|
+
* # Arguments
|
|
1340
|
+
*
|
|
1341
|
+
* * `x_json` - JSON array of predictor values (single variable)
|
|
1342
|
+
* * `fit_json` - JSON string of Polynomial fit result
|
|
1343
|
+
*
|
|
1344
|
+
* # Returns
|
|
1345
|
+
*
|
|
1346
|
+
* JSON string of [`ShapOutput`]
|
|
1347
|
+
*
|
|
1348
|
+
* # Example
|
|
1349
|
+
*
|
|
1350
|
+
* ```javascript
|
|
1351
|
+
* const fit = JSON.parse(polynomial_regression_wasm(...));
|
|
1352
|
+
* const result = JSON.parse(shap_values_polynomial(
|
|
1353
|
+
* JSON.stringify([1, 2, 3, 4, 5]),
|
|
1354
|
+
* JSON.stringify(fit)
|
|
1355
|
+
* ));
|
|
1356
|
+
* console.log(result.variable_names); // ["X¹", "X²", ...]
|
|
1357
|
+
* ```
|
|
1358
|
+
*/
|
|
1359
|
+
export function shap_values_polynomial(x_json: string, fit_json: string): string;
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* Computes SHAP (SHapley Additive exPlanations) values for Ridge regression.
|
|
1363
|
+
*
|
|
1364
|
+
* # Arguments
|
|
1365
|
+
*
|
|
1366
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
1367
|
+
* * `fit_json` - JSON string of Ridge fit result
|
|
1368
|
+
*
|
|
1369
|
+
* # Returns
|
|
1370
|
+
*
|
|
1371
|
+
* JSON string of [`ShapOutput`]
|
|
1372
|
+
*
|
|
1373
|
+
* # Example
|
|
1374
|
+
*
|
|
1375
|
+
* ```javascript
|
|
1376
|
+
* const fit = JSON.parse(ridge_regression(...));
|
|
1377
|
+
* const result = JSON.parse(shap_values_ridge(
|
|
1378
|
+
* JSON.stringify([[1,2,3], [2,4,6]]),
|
|
1379
|
+
* JSON.stringify(fit)
|
|
1380
|
+
* ));
|
|
1381
|
+
* console.log(result.mean_abs_shap);
|
|
1382
|
+
* ```
|
|
1383
|
+
*/
|
|
1384
|
+
export function shap_values_ridge(x_json: string, fit_json: string): string;
|
|
1385
|
+
|
|
1132
1386
|
/**
|
|
1133
1387
|
* Performs the Shapiro-Wilk test for normality via WASM.
|
|
1134
1388
|
*
|
|
@@ -1194,6 +1448,48 @@ export function standardized_coefficients(x_json: string, coefficients_json: str
|
|
|
1194
1448
|
*/
|
|
1195
1449
|
export function stats_correlation(x_json: string, y_json: string): string;
|
|
1196
1450
|
|
|
1451
|
+
/**
|
|
1452
|
+
* Computes the five-number summary of a JSON array of f64 values.
|
|
1453
|
+
*
|
|
1454
|
+
* The five-number summary consists of: minimum, Q1 (25th percentile),
|
|
1455
|
+
* median (50th percentile), Q3 (75th percentile), and maximum.
|
|
1456
|
+
*
|
|
1457
|
+
* # Arguments
|
|
1458
|
+
*
|
|
1459
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
1460
|
+
*
|
|
1461
|
+
* # Returns
|
|
1462
|
+
*
|
|
1463
|
+
* JSON string with the five-number summary (min, q1, median, q3, max),
|
|
1464
|
+
* or error JSON if input is invalid/empty
|
|
1465
|
+
*
|
|
1466
|
+
* # Example
|
|
1467
|
+
*
|
|
1468
|
+
* ```javascript
|
|
1469
|
+
* const result = JSON.parse(stats_five_number_summary("[1, 2, 3, 4, 5, 6, 7, 8, 9]"));
|
|
1470
|
+
* console.log(result.min); // 1
|
|
1471
|
+
* console.log(result.q1); // ~3
|
|
1472
|
+
* console.log(result.median); // 5
|
|
1473
|
+
* console.log(result.q3); // ~7
|
|
1474
|
+
* console.log(result.max); // 9
|
|
1475
|
+
* console.log(result.iqr); // ~4 (calculated as q3 - q1)
|
|
1476
|
+
* ```
|
|
1477
|
+
*/
|
|
1478
|
+
export function stats_five_number_summary(data_json: string): string;
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* Computes the maximum value of a JSON array of f64 values.
|
|
1482
|
+
*
|
|
1483
|
+
* # Arguments
|
|
1484
|
+
*
|
|
1485
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
1486
|
+
*
|
|
1487
|
+
* # Returns
|
|
1488
|
+
*
|
|
1489
|
+
* JSON string with the maximum value, or "null" if input is invalid/empty
|
|
1490
|
+
*/
|
|
1491
|
+
export function stats_max(data_json: string): string;
|
|
1492
|
+
|
|
1197
1493
|
/**
|
|
1198
1494
|
* Computes the arithmetic mean of a JSON array of f64 values.
|
|
1199
1495
|
*
|
|
@@ -1220,6 +1516,43 @@ export function stats_mean(data_json: string): string;
|
|
|
1220
1516
|
*/
|
|
1221
1517
|
export function stats_median(data_json: string): string;
|
|
1222
1518
|
|
|
1519
|
+
/**
|
|
1520
|
+
* Computes the minimum value of a JSON array of f64 values.
|
|
1521
|
+
*
|
|
1522
|
+
* # Arguments
|
|
1523
|
+
*
|
|
1524
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
1525
|
+
*
|
|
1526
|
+
* # Returns
|
|
1527
|
+
*
|
|
1528
|
+
* JSON string with the minimum value, or "null" if input is invalid/empty
|
|
1529
|
+
*/
|
|
1530
|
+
export function stats_min(data_json: string): string;
|
|
1531
|
+
|
|
1532
|
+
/**
|
|
1533
|
+
* Computes the mode(s) of a JSON array of f64 values.
|
|
1534
|
+
*
|
|
1535
|
+
* Returns all values that appear most frequently (handles ties).
|
|
1536
|
+
*
|
|
1537
|
+
* # Arguments
|
|
1538
|
+
*
|
|
1539
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
1540
|
+
*
|
|
1541
|
+
* # Returns
|
|
1542
|
+
*
|
|
1543
|
+
* JSON string with mode result containing modes array, frequency, and unique count,
|
|
1544
|
+
* or "null" if input is invalid/empty
|
|
1545
|
+
*
|
|
1546
|
+
* # Example
|
|
1547
|
+
*
|
|
1548
|
+
* ```javascript
|
|
1549
|
+
* const result = JSON.parse(stats_mode("[1, 2, 2, 3, 4]"));
|
|
1550
|
+
* console.log(result.modes); // [2]
|
|
1551
|
+
* console.log(result.frequency); // 2
|
|
1552
|
+
* ```
|
|
1553
|
+
*/
|
|
1554
|
+
export function stats_mode(data_json: string): string;
|
|
1555
|
+
|
|
1223
1556
|
/**
|
|
1224
1557
|
* Computes a quantile of a JSON array of f64 values.
|
|
1225
1558
|
*
|
|
@@ -1234,6 +1567,19 @@ export function stats_median(data_json: string): string;
|
|
|
1234
1567
|
*/
|
|
1235
1568
|
export function stats_quantile(data_json: string, q: number): string;
|
|
1236
1569
|
|
|
1570
|
+
/**
|
|
1571
|
+
* Computes the range (max - min) of a JSON array of f64 values.
|
|
1572
|
+
*
|
|
1573
|
+
* # Arguments
|
|
1574
|
+
*
|
|
1575
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
1576
|
+
*
|
|
1577
|
+
* # Returns
|
|
1578
|
+
*
|
|
1579
|
+
* JSON string with the range, or "null" if input is invalid/empty
|
|
1580
|
+
*/
|
|
1581
|
+
export function stats_range(data_json: string): string;
|
|
1582
|
+
|
|
1237
1583
|
/**
|
|
1238
1584
|
* Computes the sample standard deviation of a JSON array of f64 values.
|
|
1239
1585
|
*
|
|
@@ -1467,7 +1813,11 @@ export interface InitOutput {
|
|
|
1467
1813
|
readonly ols_prediction_intervals: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
1468
1814
|
readonly ols_regression: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1469
1815
|
readonly parse_csv: (a: number, b: number) => [number, number];
|
|
1816
|
+
readonly permutation_importance_elastic_net: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint, i: number, j: number) => [number, number];
|
|
1817
|
+
readonly permutation_importance_lasso: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint, i: number, j: number) => [number, number];
|
|
1818
|
+
readonly permutation_importance_loess: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint) => [number, number];
|
|
1470
1819
|
readonly permutation_importance_ols: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint) => [number, number];
|
|
1820
|
+
readonly permutation_importance_ridge: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint, i: number, j: number) => [number, number];
|
|
1471
1821
|
readonly polynomial_elastic_net_wasm: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number];
|
|
1472
1822
|
readonly polynomial_lasso_wasm: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
|
|
1473
1823
|
readonly polynomial_predict_wasm: (a: number, b: number, c: number, d: number) => [number, number];
|
|
@@ -1480,13 +1830,22 @@ export interface InitOutput {
|
|
|
1480
1830
|
readonly ridge_prediction_intervals: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number];
|
|
1481
1831
|
readonly ridge_regression: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
|
|
1482
1832
|
readonly serialize_model: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1833
|
+
readonly shap_values_elastic_net: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1834
|
+
readonly shap_values_lasso: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1483
1835
|
readonly shap_values_linear: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
1836
|
+
readonly shap_values_polynomial: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1837
|
+
readonly shap_values_ridge: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1484
1838
|
readonly shapiro_wilk_test: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1485
1839
|
readonly standardized_coefficients: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
1486
1840
|
readonly stats_correlation: (a: number, b: number, c: number, d: number) => [number, number];
|
|
1841
|
+
readonly stats_five_number_summary: (a: number, b: number) => [number, number];
|
|
1842
|
+
readonly stats_max: (a: number, b: number) => [number, number];
|
|
1487
1843
|
readonly stats_mean: (a: number, b: number) => [number, number];
|
|
1488
1844
|
readonly stats_median: (a: number, b: number) => [number, number];
|
|
1845
|
+
readonly stats_min: (a: number, b: number) => [number, number];
|
|
1846
|
+
readonly stats_mode: (a: number, b: number) => [number, number];
|
|
1489
1847
|
readonly stats_quantile: (a: number, b: number, c: number) => [number, number];
|
|
1848
|
+
readonly stats_range: (a: number, b: number) => [number, number];
|
|
1490
1849
|
readonly stats_stddev: (a: number, b: number) => [number, number];
|
|
1491
1850
|
readonly stats_variance: (a: number, b: number) => [number, number];
|
|
1492
1851
|
readonly test: () => [number, number];
|
package/linreg_core.js
CHANGED
|
@@ -1382,6 +1382,194 @@ export function parse_csv(content) {
|
|
|
1382
1382
|
}
|
|
1383
1383
|
}
|
|
1384
1384
|
|
|
1385
|
+
/**
|
|
1386
|
+
* Computes permutation importance for Elastic Net regression.
|
|
1387
|
+
*
|
|
1388
|
+
* # Arguments
|
|
1389
|
+
*
|
|
1390
|
+
* * `y_json` - JSON array of response values
|
|
1391
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
1392
|
+
* * `fit_json` - JSON string of Elastic Net fit result
|
|
1393
|
+
* * `n_permutations` - Number of permutation iterations
|
|
1394
|
+
* * `seed` - Random seed (use 0 for no seed)
|
|
1395
|
+
* * `compute_intervals` - Whether to compute confidence intervals
|
|
1396
|
+
* * `interval_confidence` - Confidence level for intervals (0-1)
|
|
1397
|
+
*
|
|
1398
|
+
* # Returns
|
|
1399
|
+
*
|
|
1400
|
+
* JSON string of [`PermutationImportanceOutput`]
|
|
1401
|
+
*
|
|
1402
|
+
* # Example
|
|
1403
|
+
*
|
|
1404
|
+
* ```javascript
|
|
1405
|
+
* const y = [2.5, 3.7, 4.2, 5.1, 6.3];
|
|
1406
|
+
* const x = [[1,2,3,4,5], [2,4,5,4,3]];
|
|
1407
|
+
* const fit = JSON.parse(elastic_net_regression(...));
|
|
1408
|
+
*
|
|
1409
|
+
* const result = JSON.parse(permutation_importance_elastic_net(
|
|
1410
|
+
* JSON.stringify(y),
|
|
1411
|
+
* JSON.stringify(x),
|
|
1412
|
+
* JSON.stringify(fit),
|
|
1413
|
+
* 50, // n_permutations
|
|
1414
|
+
* 42, // seed
|
|
1415
|
+
* true, // compute_intervals
|
|
1416
|
+
* 0.95 // interval_confidence
|
|
1417
|
+
* ));
|
|
1418
|
+
* console.log(result.importance);
|
|
1419
|
+
* ```
|
|
1420
|
+
* @param {string} y_json
|
|
1421
|
+
* @param {string} x_json
|
|
1422
|
+
* @param {string} fit_json
|
|
1423
|
+
* @param {number} n_permutations
|
|
1424
|
+
* @param {bigint} seed
|
|
1425
|
+
* @param {boolean} compute_intervals
|
|
1426
|
+
* @param {number} interval_confidence
|
|
1427
|
+
* @returns {string}
|
|
1428
|
+
*/
|
|
1429
|
+
export function permutation_importance_elastic_net(y_json, x_json, fit_json, n_permutations, seed, compute_intervals, interval_confidence) {
|
|
1430
|
+
let deferred4_0;
|
|
1431
|
+
let deferred4_1;
|
|
1432
|
+
try {
|
|
1433
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1434
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1435
|
+
const ptr1 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1436
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1437
|
+
const ptr2 = passStringToWasm0(fit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1438
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1439
|
+
const ret = wasm.permutation_importance_elastic_net(ptr0, len0, ptr1, len1, ptr2, len2, n_permutations, seed, compute_intervals, interval_confidence);
|
|
1440
|
+
deferred4_0 = ret[0];
|
|
1441
|
+
deferred4_1 = ret[1];
|
|
1442
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1443
|
+
} finally {
|
|
1444
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* Computes permutation importance for Lasso regression.
|
|
1450
|
+
*
|
|
1451
|
+
* # Arguments
|
|
1452
|
+
*
|
|
1453
|
+
* * `y_json` - JSON array of response values
|
|
1454
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
1455
|
+
* * `fit_json` - JSON string of Lasso fit result
|
|
1456
|
+
* * `n_permutations` - Number of permutation iterations
|
|
1457
|
+
* * `seed` - Random seed (use 0 for no seed)
|
|
1458
|
+
* * `compute_intervals` - Whether to compute confidence intervals
|
|
1459
|
+
* * `interval_confidence` - Confidence level for intervals (0-1)
|
|
1460
|
+
*
|
|
1461
|
+
* # Returns
|
|
1462
|
+
*
|
|
1463
|
+
* JSON string of [`PermutationImportanceOutput`]
|
|
1464
|
+
*
|
|
1465
|
+
* # Example
|
|
1466
|
+
*
|
|
1467
|
+
* ```javascript
|
|
1468
|
+
* const y = [2.5, 3.7, 4.2, 5.1, 6.3];
|
|
1469
|
+
* const x = [[1,2,3,4,5], [2,4,5,4,3]];
|
|
1470
|
+
* const fit = JSON.parse(lasso_regression(...));
|
|
1471
|
+
*
|
|
1472
|
+
* const result = JSON.parse(permutation_importance_lasso(
|
|
1473
|
+
* JSON.stringify(y),
|
|
1474
|
+
* JSON.stringify(x),
|
|
1475
|
+
* JSON.stringify(fit),
|
|
1476
|
+
* 50, // n_permutations
|
|
1477
|
+
* 42, // seed
|
|
1478
|
+
* true, // compute_intervals
|
|
1479
|
+
* 0.95 // interval_confidence
|
|
1480
|
+
* ));
|
|
1481
|
+
* console.log(result.importance);
|
|
1482
|
+
* ```
|
|
1483
|
+
* @param {string} y_json
|
|
1484
|
+
* @param {string} x_json
|
|
1485
|
+
* @param {string} fit_json
|
|
1486
|
+
* @param {number} n_permutations
|
|
1487
|
+
* @param {bigint} seed
|
|
1488
|
+
* @param {boolean} compute_intervals
|
|
1489
|
+
* @param {number} interval_confidence
|
|
1490
|
+
* @returns {string}
|
|
1491
|
+
*/
|
|
1492
|
+
export function permutation_importance_lasso(y_json, x_json, fit_json, n_permutations, seed, compute_intervals, interval_confidence) {
|
|
1493
|
+
let deferred4_0;
|
|
1494
|
+
let deferred4_1;
|
|
1495
|
+
try {
|
|
1496
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1497
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1498
|
+
const ptr1 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1499
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1500
|
+
const ptr2 = passStringToWasm0(fit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1501
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1502
|
+
const ret = wasm.permutation_importance_lasso(ptr0, len0, ptr1, len1, ptr2, len2, n_permutations, seed, compute_intervals, interval_confidence);
|
|
1503
|
+
deferred4_0 = ret[0];
|
|
1504
|
+
deferred4_1 = ret[1];
|
|
1505
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1506
|
+
} finally {
|
|
1507
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
/**
|
|
1512
|
+
* Computes permutation importance for LOESS regression.
|
|
1513
|
+
*
|
|
1514
|
+
* # Arguments
|
|
1515
|
+
*
|
|
1516
|
+
* * `y_json` - JSON array of response values
|
|
1517
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
1518
|
+
* * `span` - Span parameter used in original fit
|
|
1519
|
+
* * `degree` - Degree of polynomial used in original fit
|
|
1520
|
+
* * `n_permutations` - Number of permutation iterations
|
|
1521
|
+
* * `seed` - Random seed (use 0 for no seed)
|
|
1522
|
+
*
|
|
1523
|
+
* # Returns
|
|
1524
|
+
*
|
|
1525
|
+
* JSON string of [`PermutationImportanceOutput`]
|
|
1526
|
+
*
|
|
1527
|
+
* # Note
|
|
1528
|
+
*
|
|
1529
|
+
* This is computationally expensive as it re-fits the LOESS model
|
|
1530
|
+
* for each permutation of each feature.
|
|
1531
|
+
*
|
|
1532
|
+
* # Example
|
|
1533
|
+
*
|
|
1534
|
+
* ```javascript
|
|
1535
|
+
* const y = [2.5, 3.7, 4.2, 5.1, 6.3];
|
|
1536
|
+
* const x = [[1,2,3,4,5]];
|
|
1537
|
+
*
|
|
1538
|
+
* const result = JSON.parse(permutation_importance_loess(
|
|
1539
|
+
* JSON.stringify(y),
|
|
1540
|
+
* JSON.stringify(x),
|
|
1541
|
+
* 0.75, // span
|
|
1542
|
+
* 1, // degree
|
|
1543
|
+
* 20, // n_permutations (fewer for LOESS since it's slow)
|
|
1544
|
+
* 42 // seed
|
|
1545
|
+
* ));
|
|
1546
|
+
* console.log(result.importance);
|
|
1547
|
+
* ```
|
|
1548
|
+
* @param {string} y_json
|
|
1549
|
+
* @param {string} x_json
|
|
1550
|
+
* @param {number} span
|
|
1551
|
+
* @param {number} degree
|
|
1552
|
+
* @param {number} n_permutations
|
|
1553
|
+
* @param {bigint} seed
|
|
1554
|
+
* @returns {string}
|
|
1555
|
+
*/
|
|
1556
|
+
export function permutation_importance_loess(y_json, x_json, span, degree, n_permutations, seed) {
|
|
1557
|
+
let deferred3_0;
|
|
1558
|
+
let deferred3_1;
|
|
1559
|
+
try {
|
|
1560
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1561
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1562
|
+
const ptr1 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1563
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1564
|
+
const ret = wasm.permutation_importance_loess(ptr0, len0, ptr1, len1, span, degree, n_permutations, seed);
|
|
1565
|
+
deferred3_0 = ret[0];
|
|
1566
|
+
deferred3_1 = ret[1];
|
|
1567
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1568
|
+
} finally {
|
|
1569
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1385
1573
|
/**
|
|
1386
1574
|
* Computes permutation importance for OLS regression.
|
|
1387
1575
|
*
|
|
@@ -1439,6 +1627,69 @@ export function permutation_importance_ols(y_json, x_json, fit_json, n_permutati
|
|
|
1439
1627
|
}
|
|
1440
1628
|
}
|
|
1441
1629
|
|
|
1630
|
+
/**
|
|
1631
|
+
* Computes permutation importance for Ridge regression.
|
|
1632
|
+
*
|
|
1633
|
+
* # Arguments
|
|
1634
|
+
*
|
|
1635
|
+
* * `y_json` - JSON array of response values
|
|
1636
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
1637
|
+
* * `fit_json` - JSON string of Ridge fit result
|
|
1638
|
+
* * `n_permutations` - Number of permutation iterations
|
|
1639
|
+
* * `seed` - Random seed (use 0 for no seed)
|
|
1640
|
+
* * `compute_intervals` - Whether to compute confidence intervals
|
|
1641
|
+
* * `interval_confidence` - Confidence level for intervals (0-1)
|
|
1642
|
+
*
|
|
1643
|
+
* # Returns
|
|
1644
|
+
*
|
|
1645
|
+
* JSON string of [`PermutationImportanceOutput`]
|
|
1646
|
+
*
|
|
1647
|
+
* # Example
|
|
1648
|
+
*
|
|
1649
|
+
* ```javascript
|
|
1650
|
+
* const y = [2.5, 3.7, 4.2, 5.1, 6.3];
|
|
1651
|
+
* const x = [[1,2,3,4,5], [2,4,5,4,3]];
|
|
1652
|
+
* const fit = JSON.parse(ridge_regression(...));
|
|
1653
|
+
*
|
|
1654
|
+
* const result = JSON.parse(permutation_importance_ridge(
|
|
1655
|
+
* JSON.stringify(y),
|
|
1656
|
+
* JSON.stringify(x),
|
|
1657
|
+
* JSON.stringify(fit),
|
|
1658
|
+
* 50, // n_permutations
|
|
1659
|
+
* 42, // seed
|
|
1660
|
+
* true, // compute_intervals
|
|
1661
|
+
* 0.95 // interval_confidence
|
|
1662
|
+
* ));
|
|
1663
|
+
* console.log(result.importance);
|
|
1664
|
+
* ```
|
|
1665
|
+
* @param {string} y_json
|
|
1666
|
+
* @param {string} x_json
|
|
1667
|
+
* @param {string} fit_json
|
|
1668
|
+
* @param {number} n_permutations
|
|
1669
|
+
* @param {bigint} seed
|
|
1670
|
+
* @param {boolean} compute_intervals
|
|
1671
|
+
* @param {number} interval_confidence
|
|
1672
|
+
* @returns {string}
|
|
1673
|
+
*/
|
|
1674
|
+
export function permutation_importance_ridge(y_json, x_json, fit_json, n_permutations, seed, compute_intervals, interval_confidence) {
|
|
1675
|
+
let deferred4_0;
|
|
1676
|
+
let deferred4_1;
|
|
1677
|
+
try {
|
|
1678
|
+
const ptr0 = passStringToWasm0(y_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1679
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1680
|
+
const ptr1 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1681
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1682
|
+
const ptr2 = passStringToWasm0(fit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1683
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1684
|
+
const ret = wasm.permutation_importance_ridge(ptr0, len0, ptr1, len1, ptr2, len2, n_permutations, seed, compute_intervals, interval_confidence);
|
|
1685
|
+
deferred4_0 = ret[0];
|
|
1686
|
+
deferred4_1 = ret[1];
|
|
1687
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
1688
|
+
} finally {
|
|
1689
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1442
1693
|
/**
|
|
1443
1694
|
* Fit polynomial Elastic Net regression via WASM.
|
|
1444
1695
|
*
|
|
@@ -1996,6 +2247,92 @@ export function serialize_model(model_json, model_type, name) {
|
|
|
1996
2247
|
}
|
|
1997
2248
|
}
|
|
1998
2249
|
|
|
2250
|
+
/**
|
|
2251
|
+
* Computes SHAP (SHapley Additive exPlanations) values for Elastic Net regression.
|
|
2252
|
+
*
|
|
2253
|
+
* # Arguments
|
|
2254
|
+
*
|
|
2255
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
2256
|
+
* * `fit_json` - JSON string of Elastic Net fit result
|
|
2257
|
+
*
|
|
2258
|
+
* # Returns
|
|
2259
|
+
*
|
|
2260
|
+
* JSON string of [`ShapOutput`]
|
|
2261
|
+
*
|
|
2262
|
+
* # Example
|
|
2263
|
+
*
|
|
2264
|
+
* ```javascript
|
|
2265
|
+
* const fit = JSON.parse(elastic_net_regression(...));
|
|
2266
|
+
* const result = JSON.parse(shap_values_elastic_net(
|
|
2267
|
+
* JSON.stringify([[1,2,3], [2,4,6]]),
|
|
2268
|
+
* JSON.stringify(fit)
|
|
2269
|
+
* ));
|
|
2270
|
+
* console.log(result.mean_abs_shap);
|
|
2271
|
+
* ```
|
|
2272
|
+
* @param {string} x_json
|
|
2273
|
+
* @param {string} fit_json
|
|
2274
|
+
* @returns {string}
|
|
2275
|
+
*/
|
|
2276
|
+
export function shap_values_elastic_net(x_json, fit_json) {
|
|
2277
|
+
let deferred3_0;
|
|
2278
|
+
let deferred3_1;
|
|
2279
|
+
try {
|
|
2280
|
+
const ptr0 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2281
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2282
|
+
const ptr1 = passStringToWasm0(fit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2283
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2284
|
+
const ret = wasm.shap_values_elastic_net(ptr0, len0, ptr1, len1);
|
|
2285
|
+
deferred3_0 = ret[0];
|
|
2286
|
+
deferred3_1 = ret[1];
|
|
2287
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2288
|
+
} finally {
|
|
2289
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
/**
|
|
2294
|
+
* Computes SHAP (SHapley Additive exPlanations) values for Lasso regression.
|
|
2295
|
+
*
|
|
2296
|
+
* # Arguments
|
|
2297
|
+
*
|
|
2298
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
2299
|
+
* * `fit_json` - JSON string of Lasso fit result
|
|
2300
|
+
*
|
|
2301
|
+
* # Returns
|
|
2302
|
+
*
|
|
2303
|
+
* JSON string of [`ShapOutput`]
|
|
2304
|
+
*
|
|
2305
|
+
* # Example
|
|
2306
|
+
*
|
|
2307
|
+
* ```javascript
|
|
2308
|
+
* const fit = JSON.parse(lasso_regression(...));
|
|
2309
|
+
* const result = JSON.parse(shap_values_lasso(
|
|
2310
|
+
* JSON.stringify([[1,2,3], [2,4,6]]),
|
|
2311
|
+
* JSON.stringify(fit)
|
|
2312
|
+
* ));
|
|
2313
|
+
* console.log(result.mean_abs_shap);
|
|
2314
|
+
* ```
|
|
2315
|
+
* @param {string} x_json
|
|
2316
|
+
* @param {string} fit_json
|
|
2317
|
+
* @returns {string}
|
|
2318
|
+
*/
|
|
2319
|
+
export function shap_values_lasso(x_json, fit_json) {
|
|
2320
|
+
let deferred3_0;
|
|
2321
|
+
let deferred3_1;
|
|
2322
|
+
try {
|
|
2323
|
+
const ptr0 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2324
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2325
|
+
const ptr1 = passStringToWasm0(fit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2326
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2327
|
+
const ret = wasm.shap_values_lasso(ptr0, len0, ptr1, len1);
|
|
2328
|
+
deferred3_0 = ret[0];
|
|
2329
|
+
deferred3_1 = ret[1];
|
|
2330
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2331
|
+
} finally {
|
|
2332
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
|
|
1999
2336
|
/**
|
|
2000
2337
|
* Computes SHAP (SHapley Additive exPlanations) values for linear models.
|
|
2001
2338
|
*
|
|
@@ -2044,6 +2381,92 @@ export function shap_values_linear(x_json, coefficients_json, variable_names_jso
|
|
|
2044
2381
|
}
|
|
2045
2382
|
}
|
|
2046
2383
|
|
|
2384
|
+
/**
|
|
2385
|
+
* Computes SHAP (SHapley Additive exPlanations) values for polynomial regression.
|
|
2386
|
+
*
|
|
2387
|
+
* # Arguments
|
|
2388
|
+
*
|
|
2389
|
+
* * `x_json` - JSON array of predictor values (single variable)
|
|
2390
|
+
* * `fit_json` - JSON string of Polynomial fit result
|
|
2391
|
+
*
|
|
2392
|
+
* # Returns
|
|
2393
|
+
*
|
|
2394
|
+
* JSON string of [`ShapOutput`]
|
|
2395
|
+
*
|
|
2396
|
+
* # Example
|
|
2397
|
+
*
|
|
2398
|
+
* ```javascript
|
|
2399
|
+
* const fit = JSON.parse(polynomial_regression_wasm(...));
|
|
2400
|
+
* const result = JSON.parse(shap_values_polynomial(
|
|
2401
|
+
* JSON.stringify([1, 2, 3, 4, 5]),
|
|
2402
|
+
* JSON.stringify(fit)
|
|
2403
|
+
* ));
|
|
2404
|
+
* console.log(result.variable_names); // ["X¹", "X²", ...]
|
|
2405
|
+
* ```
|
|
2406
|
+
* @param {string} x_json
|
|
2407
|
+
* @param {string} fit_json
|
|
2408
|
+
* @returns {string}
|
|
2409
|
+
*/
|
|
2410
|
+
export function shap_values_polynomial(x_json, fit_json) {
|
|
2411
|
+
let deferred3_0;
|
|
2412
|
+
let deferred3_1;
|
|
2413
|
+
try {
|
|
2414
|
+
const ptr0 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2415
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2416
|
+
const ptr1 = passStringToWasm0(fit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2417
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2418
|
+
const ret = wasm.shap_values_polynomial(ptr0, len0, ptr1, len1);
|
|
2419
|
+
deferred3_0 = ret[0];
|
|
2420
|
+
deferred3_1 = ret[1];
|
|
2421
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2422
|
+
} finally {
|
|
2423
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
/**
|
|
2428
|
+
* Computes SHAP (SHapley Additive exPlanations) values for Ridge regression.
|
|
2429
|
+
*
|
|
2430
|
+
* # Arguments
|
|
2431
|
+
*
|
|
2432
|
+
* * `x_json` - JSON array of predictor arrays (each array is a column)
|
|
2433
|
+
* * `fit_json` - JSON string of Ridge fit result
|
|
2434
|
+
*
|
|
2435
|
+
* # Returns
|
|
2436
|
+
*
|
|
2437
|
+
* JSON string of [`ShapOutput`]
|
|
2438
|
+
*
|
|
2439
|
+
* # Example
|
|
2440
|
+
*
|
|
2441
|
+
* ```javascript
|
|
2442
|
+
* const fit = JSON.parse(ridge_regression(...));
|
|
2443
|
+
* const result = JSON.parse(shap_values_ridge(
|
|
2444
|
+
* JSON.stringify([[1,2,3], [2,4,6]]),
|
|
2445
|
+
* JSON.stringify(fit)
|
|
2446
|
+
* ));
|
|
2447
|
+
* console.log(result.mean_abs_shap);
|
|
2448
|
+
* ```
|
|
2449
|
+
* @param {string} x_json
|
|
2450
|
+
* @param {string} fit_json
|
|
2451
|
+
* @returns {string}
|
|
2452
|
+
*/
|
|
2453
|
+
export function shap_values_ridge(x_json, fit_json) {
|
|
2454
|
+
let deferred3_0;
|
|
2455
|
+
let deferred3_1;
|
|
2456
|
+
try {
|
|
2457
|
+
const ptr0 = passStringToWasm0(x_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2458
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2459
|
+
const ptr1 = passStringToWasm0(fit_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2460
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2461
|
+
const ret = wasm.shap_values_ridge(ptr0, len0, ptr1, len1);
|
|
2462
|
+
deferred3_0 = ret[0];
|
|
2463
|
+
deferred3_1 = ret[1];
|
|
2464
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2465
|
+
} finally {
|
|
2466
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2047
2470
|
/**
|
|
2048
2471
|
* Performs the Shapiro-Wilk test for normality via WASM.
|
|
2049
2472
|
*
|
|
@@ -2167,6 +2590,78 @@ export function stats_correlation(x_json, y_json) {
|
|
|
2167
2590
|
}
|
|
2168
2591
|
}
|
|
2169
2592
|
|
|
2593
|
+
/**
|
|
2594
|
+
* Computes the five-number summary of a JSON array of f64 values.
|
|
2595
|
+
*
|
|
2596
|
+
* The five-number summary consists of: minimum, Q1 (25th percentile),
|
|
2597
|
+
* median (50th percentile), Q3 (75th percentile), and maximum.
|
|
2598
|
+
*
|
|
2599
|
+
* # Arguments
|
|
2600
|
+
*
|
|
2601
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
2602
|
+
*
|
|
2603
|
+
* # Returns
|
|
2604
|
+
*
|
|
2605
|
+
* JSON string with the five-number summary (min, q1, median, q3, max),
|
|
2606
|
+
* or error JSON if input is invalid/empty
|
|
2607
|
+
*
|
|
2608
|
+
* # Example
|
|
2609
|
+
*
|
|
2610
|
+
* ```javascript
|
|
2611
|
+
* const result = JSON.parse(stats_five_number_summary("[1, 2, 3, 4, 5, 6, 7, 8, 9]"));
|
|
2612
|
+
* console.log(result.min); // 1
|
|
2613
|
+
* console.log(result.q1); // ~3
|
|
2614
|
+
* console.log(result.median); // 5
|
|
2615
|
+
* console.log(result.q3); // ~7
|
|
2616
|
+
* console.log(result.max); // 9
|
|
2617
|
+
* console.log(result.iqr); // ~4 (calculated as q3 - q1)
|
|
2618
|
+
* ```
|
|
2619
|
+
* @param {string} data_json
|
|
2620
|
+
* @returns {string}
|
|
2621
|
+
*/
|
|
2622
|
+
export function stats_five_number_summary(data_json) {
|
|
2623
|
+
let deferred2_0;
|
|
2624
|
+
let deferred2_1;
|
|
2625
|
+
try {
|
|
2626
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2627
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2628
|
+
const ret = wasm.stats_five_number_summary(ptr0, len0);
|
|
2629
|
+
deferred2_0 = ret[0];
|
|
2630
|
+
deferred2_1 = ret[1];
|
|
2631
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2632
|
+
} finally {
|
|
2633
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
/**
|
|
2638
|
+
* Computes the maximum value of a JSON array of f64 values.
|
|
2639
|
+
*
|
|
2640
|
+
* # Arguments
|
|
2641
|
+
*
|
|
2642
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
2643
|
+
*
|
|
2644
|
+
* # Returns
|
|
2645
|
+
*
|
|
2646
|
+
* JSON string with the maximum value, or "null" if input is invalid/empty
|
|
2647
|
+
* @param {string} data_json
|
|
2648
|
+
* @returns {string}
|
|
2649
|
+
*/
|
|
2650
|
+
export function stats_max(data_json) {
|
|
2651
|
+
let deferred2_0;
|
|
2652
|
+
let deferred2_1;
|
|
2653
|
+
try {
|
|
2654
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2655
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2656
|
+
const ret = wasm.stats_max(ptr0, len0);
|
|
2657
|
+
deferred2_0 = ret[0];
|
|
2658
|
+
deferred2_1 = ret[1];
|
|
2659
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2660
|
+
} finally {
|
|
2661
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2170
2665
|
/**
|
|
2171
2666
|
* Computes the arithmetic mean of a JSON array of f64 values.
|
|
2172
2667
|
*
|
|
@@ -2223,6 +2718,73 @@ export function stats_median(data_json) {
|
|
|
2223
2718
|
}
|
|
2224
2719
|
}
|
|
2225
2720
|
|
|
2721
|
+
/**
|
|
2722
|
+
* Computes the minimum value of a JSON array of f64 values.
|
|
2723
|
+
*
|
|
2724
|
+
* # Arguments
|
|
2725
|
+
*
|
|
2726
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
2727
|
+
*
|
|
2728
|
+
* # Returns
|
|
2729
|
+
*
|
|
2730
|
+
* JSON string with the minimum value, or "null" if input is invalid/empty
|
|
2731
|
+
* @param {string} data_json
|
|
2732
|
+
* @returns {string}
|
|
2733
|
+
*/
|
|
2734
|
+
export function stats_min(data_json) {
|
|
2735
|
+
let deferred2_0;
|
|
2736
|
+
let deferred2_1;
|
|
2737
|
+
try {
|
|
2738
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2739
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2740
|
+
const ret = wasm.stats_min(ptr0, len0);
|
|
2741
|
+
deferred2_0 = ret[0];
|
|
2742
|
+
deferred2_1 = ret[1];
|
|
2743
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2744
|
+
} finally {
|
|
2745
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
/**
|
|
2750
|
+
* Computes the mode(s) of a JSON array of f64 values.
|
|
2751
|
+
*
|
|
2752
|
+
* Returns all values that appear most frequently (handles ties).
|
|
2753
|
+
*
|
|
2754
|
+
* # Arguments
|
|
2755
|
+
*
|
|
2756
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
2757
|
+
*
|
|
2758
|
+
* # Returns
|
|
2759
|
+
*
|
|
2760
|
+
* JSON string with mode result containing modes array, frequency, and unique count,
|
|
2761
|
+
* or "null" if input is invalid/empty
|
|
2762
|
+
*
|
|
2763
|
+
* # Example
|
|
2764
|
+
*
|
|
2765
|
+
* ```javascript
|
|
2766
|
+
* const result = JSON.parse(stats_mode("[1, 2, 2, 3, 4]"));
|
|
2767
|
+
* console.log(result.modes); // [2]
|
|
2768
|
+
* console.log(result.frequency); // 2
|
|
2769
|
+
* ```
|
|
2770
|
+
* @param {string} data_json
|
|
2771
|
+
* @returns {string}
|
|
2772
|
+
*/
|
|
2773
|
+
export function stats_mode(data_json) {
|
|
2774
|
+
let deferred2_0;
|
|
2775
|
+
let deferred2_1;
|
|
2776
|
+
try {
|
|
2777
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2778
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2779
|
+
const ret = wasm.stats_mode(ptr0, len0);
|
|
2780
|
+
deferred2_0 = ret[0];
|
|
2781
|
+
deferred2_1 = ret[1];
|
|
2782
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2783
|
+
} finally {
|
|
2784
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2226
2788
|
/**
|
|
2227
2789
|
* Computes a quantile of a JSON array of f64 values.
|
|
2228
2790
|
*
|
|
@@ -2253,6 +2815,34 @@ export function stats_quantile(data_json, q) {
|
|
|
2253
2815
|
}
|
|
2254
2816
|
}
|
|
2255
2817
|
|
|
2818
|
+
/**
|
|
2819
|
+
* Computes the range (max - min) of a JSON array of f64 values.
|
|
2820
|
+
*
|
|
2821
|
+
* # Arguments
|
|
2822
|
+
*
|
|
2823
|
+
* * `data_json` - JSON string representing an array of f64 values
|
|
2824
|
+
*
|
|
2825
|
+
* # Returns
|
|
2826
|
+
*
|
|
2827
|
+
* JSON string with the range, or "null" if input is invalid/empty
|
|
2828
|
+
* @param {string} data_json
|
|
2829
|
+
* @returns {string}
|
|
2830
|
+
*/
|
|
2831
|
+
export function stats_range(data_json) {
|
|
2832
|
+
let deferred2_0;
|
|
2833
|
+
let deferred2_1;
|
|
2834
|
+
try {
|
|
2835
|
+
const ptr0 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2836
|
+
const len0 = WASM_VECTOR_LEN;
|
|
2837
|
+
const ret = wasm.stats_range(ptr0, len0);
|
|
2838
|
+
deferred2_0 = ret[0];
|
|
2839
|
+
deferred2_1 = ret[1];
|
|
2840
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
2841
|
+
} finally {
|
|
2842
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
|
|
2256
2846
|
/**
|
|
2257
2847
|
* Computes the sample standard deviation of a JSON array of f64 values.
|
|
2258
2848
|
*
|
package/linreg_core_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"collaborators": [
|
|
5
5
|
"Jesse Anderson"
|
|
6
6
|
],
|
|
7
|
-
"description": "Lightweight
|
|
8
|
-
"version": "0.8.
|
|
7
|
+
"description": "Lightweight regression library (OLS, Ridge, Lasso, Elastic Net, WLS, LOESS, Polynomial) with 14 diagnostic tests, cross validation, and prediction intervals. Pure Rust - no external math dependencies. WASM, Python, FFI, and Excel XLL bindings.",
|
|
8
|
+
"version": "0.8.1",
|
|
9
9
|
"license": "MIT OR Apache-2.0",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"regression",
|
|
29
29
|
"statistics",
|
|
30
30
|
"linear-regression",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"diagnostics",
|
|
32
|
+
"excel"
|
|
33
33
|
]
|
|
34
34
|
}
|