-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
LogisticRegressionCV.ts
1009 lines (820 loc) · 36.2 KB
/
LogisticRegressionCV.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable */
/* NOTE: This file is auto-generated. Do not edit it directly. */
import crypto from 'node:crypto'
import { PythonBridge, NDArray, ArrayLike, SparseMatrix } from '@/sklearn/types'
/**
Logistic Regression CV (aka logit, MaxEnt) classifier.
See glossary entry for [cross-validation estimator](../../glossary.html#term-cross-validation-estimator).
This class implements logistic regression using liblinear, newton-cg, sag of lbfgs optimizer. The newton-cg, sag and lbfgs solvers support only L2 regularization with primal formulation. The liblinear solver supports both L1 and L2 regularization, with a dual formulation only for the L2 penalty. Elastic-Net penalty is only supported by the saga solver.
For the grid of `Cs` values and `l1\_ratios` values, the best hyperparameter is selected by the cross-validator [`StratifiedKFold`](sklearn.model_selection.StratifiedKFold.html#sklearn.model_selection.StratifiedKFold "sklearn.model_selection.StratifiedKFold"), but it can be changed using the [cv](../../glossary.html#term-cv) parameter. The ‘newton-cg’, ‘sag’, ‘saga’ and ‘lbfgs’ solvers can warm-start the coefficients (see [Glossary](../../glossary.html#term-warm_start)).
Read more in the [User Guide](../linear_model.html#logistic-regression).
[Python Reference](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html)
*/
export class LogisticRegressionCV {
id: string
opts: any
_py: PythonBridge
_isInitialized: boolean = false
_isDisposed: boolean = false
constructor(opts?: {
/**
Each of the values in Cs describes the inverse of regularization strength. If Cs is as an int, then a grid of Cs values are chosen in a logarithmic scale between 1e-4 and 1e4. Like in support vector machines, smaller values specify stronger regularization.
@defaultValue `10`
*/
Cs?: number
/**
Specifies if a constant (a.k.a. bias or intercept) should be added to the decision function.
@defaultValue `true`
*/
fit_intercept?: boolean
/**
The default cross-validation generator used is Stratified K-Folds. If an integer is provided, then it is the number of folds used. See the module [`sklearn.model\_selection`](../classes.html#module-sklearn.model_selection "sklearn.model_selection") module for the list of possible cross-validation objects.
*/
cv?: number
/**
Dual (constrained) or primal (regularized, see also [this equation](../linear_model.html#regularized-logistic-loss)) formulation. Dual formulation is only implemented for l2 penalty with liblinear solver. Prefer dual=`false` when n\_samples > n\_features.
@defaultValue `false`
*/
dual?: boolean
/**
Specify the norm of the penalty:
@defaultValue `'l2'`
*/
penalty?: 'l1' | 'l2' | 'elasticnet'
/**
A string (see model evaluation documentation) or a scorer callable object / function with signature `scorer(estimator, X, y)`. For a list of scoring functions that can be used, look at [`sklearn.metrics`](../classes.html#module-sklearn.metrics "sklearn.metrics"). The default scoring option used is ‘accuracy’.
*/
scoring?: string
/**
Algorithm to use in the optimization problem. Default is ‘lbfgs’. To choose a solver, you might want to consider the following aspects:
@defaultValue `'lbfgs'`
*/
solver?:
| 'lbfgs'
| 'liblinear'
| 'newton-cg'
| 'newton-cholesky'
| 'sag'
| 'saga'
/**
Tolerance for stopping criteria.
@defaultValue `0.0001`
*/
tol?: number
/**
Maximum number of iterations of the optimization algorithm.
@defaultValue `100`
*/
max_iter?: number
/**
Weights associated with classes in the form `{class\_label: weight}`. If not given, all classes are supposed to have weight one.
The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as `n\_samples / (n\_classes \* np.bincount(y))`.
Note that these weights will be multiplied with sample\_weight (passed through the fit method) if sample\_weight is specified.
*/
class_weight?: any | 'balanced'
/**
Number of CPU cores used during the cross-validation loop. `undefined` means 1 unless in a [`joblib.parallel\_backend`](https://joblib.readthedocs.io/en/latest/generated/joblib.parallel_backend.html#joblib.parallel_backend "(in joblib v1.4.dev0)") context. `\-1` means using all processors. See [Glossary](../../glossary.html#term-n_jobs) for more details.
*/
n_jobs?: number
/**
For the ‘liblinear’, ‘sag’ and ‘lbfgs’ solvers set verbose to any positive number for verbosity.
@defaultValue `0`
*/
verbose?: number
/**
If set to `true`, the scores are averaged across all folds, and the coefs and the C that corresponds to the best score is taken, and a final refit is done using these parameters. Otherwise the coefs, intercepts and C that correspond to the best scores across folds are averaged.
@defaultValue `true`
*/
refit?: boolean
/**
Useful only when the solver ‘liblinear’ is used and self.fit\_intercept is set to `true`. In this case, x becomes \[x, self.intercept\_scaling\], i.e. a “synthetic” feature with constant value equal to intercept\_scaling is appended to the instance vector. The intercept becomes `intercept\_scaling \* synthetic\_feature\_weight`.
Note! the synthetic feature weight is subject to l1/l2 regularization as all other features. To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept\_scaling has to be increased.
@defaultValue `1`
*/
intercept_scaling?: number
/**
If the option chosen is ‘ovr’, then a binary problem is fit for each label. For ‘multinomial’ the loss minimised is the multinomial loss fit across the entire probability distribution, *even when the data is binary*. ‘multinomial’ is unavailable when solver=’liblinear’. ‘auto’ selects ‘ovr’ if the data is binary, or if solver=’liblinear’, and otherwise selects ‘multinomial’.
@defaultValue `'auto'`
*/
multi_class?: 'ovr' | 'multinomial'
/**
Used when `solver='sag'`, ‘saga’ or ‘liblinear’ to shuffle the data. Note that this only applies to the solver and not the cross-validation generator. See [Glossary](../../glossary.html#term-random_state) for details.
*/
random_state?: number
/**
The list of Elastic-Net mixing parameter, with `0 <= l1\_ratio <= 1`. Only used if `penalty='elasticnet'`. A value of 0 is equivalent to using `penalty='l2'`, while 1 is equivalent to using `penalty='l1'`. For `0 < l1\_ratio <1`, the penalty is a combination of L1 and L2.
*/
l1_ratios?: any
}) {
this.id = `LogisticRegressionCV${crypto.randomUUID().split('-')[0]}`
this.opts = opts || {}
}
get py(): PythonBridge {
return this._py
}
set py(pythonBridge: PythonBridge) {
this._py = pythonBridge
}
/**
Initializes the underlying Python resources.
This instance is not usable until the `Promise` returned by `init()` resolves.
*/
async init(py: PythonBridge): Promise<void> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (this._isInitialized) {
return
}
if (!py) {
throw new Error(
'LogisticRegressionCV.init requires a PythonBridge instance'
)
}
this._py = py
await this._py.ex`
import numpy as np
from sklearn.linear_model import LogisticRegressionCV
try: bridgeLogisticRegressionCV
except NameError: bridgeLogisticRegressionCV = {}
`
// set up constructor params
await this._py.ex`ctor_LogisticRegressionCV = {'Cs': ${
this.opts['Cs'] ?? undefined
}, 'fit_intercept': ${this.opts['fit_intercept'] ?? undefined}, 'cv': ${
this.opts['cv'] ?? undefined
}, 'dual': ${this.opts['dual'] ?? undefined}, 'penalty': ${
this.opts['penalty'] ?? undefined
}, 'scoring': ${this.opts['scoring'] ?? undefined}, 'solver': ${
this.opts['solver'] ?? undefined
}, 'tol': ${this.opts['tol'] ?? undefined}, 'max_iter': ${
this.opts['max_iter'] ?? undefined
}, 'class_weight': ${this.opts['class_weight'] ?? undefined}, 'n_jobs': ${
this.opts['n_jobs'] ?? undefined
}, 'verbose': ${this.opts['verbose'] ?? undefined}, 'refit': ${
this.opts['refit'] ?? undefined
}, 'intercept_scaling': ${
this.opts['intercept_scaling'] ?? undefined
}, 'multi_class': ${
this.opts['multi_class'] ?? undefined
}, 'random_state': ${
this.opts['random_state'] ?? undefined
}, 'l1_ratios': ${this.opts['l1_ratios'] ?? undefined}}
ctor_LogisticRegressionCV = {k: v for k, v in ctor_LogisticRegressionCV.items() if v is not None}`
await this._py
.ex`bridgeLogisticRegressionCV[${this.id}] = LogisticRegressionCV(**ctor_LogisticRegressionCV)`
this._isInitialized = true
}
/**
Disposes of the underlying Python resources.
Once `dispose()` is called, the instance is no longer usable.
*/
async dispose() {
if (this._isDisposed) {
return
}
if (!this._isInitialized) {
return
}
await this._py.ex`del bridgeLogisticRegressionCV[${this.id}]`
this._isDisposed = true
}
/**
Predict confidence scores for samples.
The confidence score for a sample is proportional to the signed distance of that sample to the hyperplane.
*/
async decision_function(opts: {
/**
The data matrix for which we want to get the confidence scores.
*/
X?: ArrayLike | SparseMatrix[]
}): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before decision_function()'
)
}
// set up method params
await this._py
.ex`pms_LogisticRegressionCV_decision_function = {'X': np.array(${
opts['X'] ?? undefined
}) if ${opts['X'] !== undefined} else None}
pms_LogisticRegressionCV_decision_function = {k: v for k, v in pms_LogisticRegressionCV_decision_function.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_decision_function = bridgeLogisticRegressionCV[${this.id}].decision_function(**pms_LogisticRegressionCV_decision_function)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_decision_function.tolist() if hasattr(res_LogisticRegressionCV_decision_function, 'tolist') else res_LogisticRegressionCV_decision_function`
}
/**
Convert coefficient matrix to dense array format.
Converts the `coef\_` member (back) to a numpy.ndarray. This is the default format of `coef\_` and is required for fitting, so calling this method is only required on models that have previously been sparsified; otherwise, it is a no-op.
*/
async densify(opts: {}): Promise<any> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error('LogisticRegressionCV must call init() before densify()')
}
// set up method params
await this._py.ex`pms_LogisticRegressionCV_densify = {}
pms_LogisticRegressionCV_densify = {k: v for k, v in pms_LogisticRegressionCV_densify.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_densify = bridgeLogisticRegressionCV[${this.id}].densify(**pms_LogisticRegressionCV_densify)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_densify.tolist() if hasattr(res_LogisticRegressionCV_densify, 'tolist') else res_LogisticRegressionCV_densify`
}
/**
Fit the model according to the given training data.
*/
async fit(opts: {
/**
Training vector, where `n\_samples` is the number of samples and `n\_features` is the number of features.
*/
X?: ArrayLike | SparseMatrix[]
/**
Target vector relative to X.
*/
y?: ArrayLike
/**
Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
*/
sample_weight?: any
}): Promise<any> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error('LogisticRegressionCV must call init() before fit()')
}
// set up method params
await this._py.ex`pms_LogisticRegressionCV_fit = {'X': np.array(${
opts['X'] ?? undefined
}) if ${opts['X'] !== undefined} else None, 'y': np.array(${
opts['y'] ?? undefined
}) if ${opts['y'] !== undefined} else None, 'sample_weight': np.array(${
opts['sample_weight'] ?? undefined
}) if ${opts['sample_weight'] !== undefined} else None}
pms_LogisticRegressionCV_fit = {k: v for k, v in pms_LogisticRegressionCV_fit.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_fit = bridgeLogisticRegressionCV[${this.id}].fit(**pms_LogisticRegressionCV_fit)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_fit.tolist() if hasattr(res_LogisticRegressionCV_fit, 'tolist') else res_LogisticRegressionCV_fit`
}
/**
Get metadata routing of this object.
Please check [User Guide](../../metadata_routing.html#metadata-routing) on how the routing mechanism works.
*/
async get_metadata_routing(opts: {
/**
A [`MetadataRequest`](sklearn.utils.metadata_routing.MetadataRequest.html#sklearn.utils.metadata_routing.MetadataRequest "sklearn.utils.metadata_routing.MetadataRequest") encapsulating routing information.
*/
routing?: any
}): Promise<any> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before get_metadata_routing()'
)
}
// set up method params
await this._py
.ex`pms_LogisticRegressionCV_get_metadata_routing = {'routing': ${
opts['routing'] ?? undefined
}}
pms_LogisticRegressionCV_get_metadata_routing = {k: v for k, v in pms_LogisticRegressionCV_get_metadata_routing.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_get_metadata_routing = bridgeLogisticRegressionCV[${this.id}].get_metadata_routing(**pms_LogisticRegressionCV_get_metadata_routing)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_get_metadata_routing.tolist() if hasattr(res_LogisticRegressionCV_get_metadata_routing, 'tolist') else res_LogisticRegressionCV_get_metadata_routing`
}
/**
Predict class labels for samples in X.
*/
async predict(opts: {
/**
The data matrix for which we want to get the predictions.
*/
X?: ArrayLike | SparseMatrix[]
}): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error('LogisticRegressionCV must call init() before predict()')
}
// set up method params
await this._py.ex`pms_LogisticRegressionCV_predict = {'X': np.array(${
opts['X'] ?? undefined
}) if ${opts['X'] !== undefined} else None}
pms_LogisticRegressionCV_predict = {k: v for k, v in pms_LogisticRegressionCV_predict.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_predict = bridgeLogisticRegressionCV[${this.id}].predict(**pms_LogisticRegressionCV_predict)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_predict.tolist() if hasattr(res_LogisticRegressionCV_predict, 'tolist') else res_LogisticRegressionCV_predict`
}
/**
Predict logarithm of probability estimates.
The returned estimates for all classes are ordered by the label of classes.
*/
async predict_log_proba(opts: {
/**
Vector to be scored, where `n\_samples` is the number of samples and `n\_features` is the number of features.
*/
X?: ArrayLike[]
}): Promise<ArrayLike[]> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before predict_log_proba()'
)
}
// set up method params
await this._py
.ex`pms_LogisticRegressionCV_predict_log_proba = {'X': np.array(${
opts['X'] ?? undefined
}) if ${opts['X'] !== undefined} else None}
pms_LogisticRegressionCV_predict_log_proba = {k: v for k, v in pms_LogisticRegressionCV_predict_log_proba.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_predict_log_proba = bridgeLogisticRegressionCV[${this.id}].predict_log_proba(**pms_LogisticRegressionCV_predict_log_proba)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_predict_log_proba.tolist() if hasattr(res_LogisticRegressionCV_predict_log_proba, 'tolist') else res_LogisticRegressionCV_predict_log_proba`
}
/**
Probability estimates.
The returned estimates for all classes are ordered by the label of classes.
For a multi\_class problem, if multi\_class is set to be “multinomial” the softmax function is used to find the predicted probability of each class. Else use a one-vs-rest approach, i.e calculate the probability of each class assuming it to be positive using the logistic function. and normalize these values across all the classes.
*/
async predict_proba(opts: {
/**
Vector to be scored, where `n\_samples` is the number of samples and `n\_features` is the number of features.
*/
X?: ArrayLike[]
}): Promise<ArrayLike[]> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before predict_proba()'
)
}
// set up method params
await this._py.ex`pms_LogisticRegressionCV_predict_proba = {'X': np.array(${
opts['X'] ?? undefined
}) if ${opts['X'] !== undefined} else None}
pms_LogisticRegressionCV_predict_proba = {k: v for k, v in pms_LogisticRegressionCV_predict_proba.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_predict_proba = bridgeLogisticRegressionCV[${this.id}].predict_proba(**pms_LogisticRegressionCV_predict_proba)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_predict_proba.tolist() if hasattr(res_LogisticRegressionCV_predict_proba, 'tolist') else res_LogisticRegressionCV_predict_proba`
}
/**
Score using the `scoring` option on the given test data and labels.
*/
async score(opts: {
/**
Test samples.
*/
X?: ArrayLike[]
/**
True labels for X.
*/
y?: ArrayLike
/**
Sample weights.
*/
sample_weight?: ArrayLike
}): Promise<number> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error('LogisticRegressionCV must call init() before score()')
}
// set up method params
await this._py.ex`pms_LogisticRegressionCV_score = {'X': np.array(${
opts['X'] ?? undefined
}) if ${opts['X'] !== undefined} else None, 'y': np.array(${
opts['y'] ?? undefined
}) if ${opts['y'] !== undefined} else None, 'sample_weight': np.array(${
opts['sample_weight'] ?? undefined
}) if ${opts['sample_weight'] !== undefined} else None}
pms_LogisticRegressionCV_score = {k: v for k, v in pms_LogisticRegressionCV_score.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_score = bridgeLogisticRegressionCV[${this.id}].score(**pms_LogisticRegressionCV_score)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_score.tolist() if hasattr(res_LogisticRegressionCV_score, 'tolist') else res_LogisticRegressionCV_score`
}
/**
Request metadata passed to the `fit` method.
Note that this method is only relevant if `enable\_metadata\_routing=True` (see [`sklearn.set\_config`](sklearn.set_config.html#sklearn.set_config "sklearn.set_config")). Please see [User Guide](../../metadata_routing.html#metadata-routing) on how the routing mechanism works.
The options for each parameter are:
*/
async set_fit_request(opts: {
/**
Metadata routing for `sample\_weight` parameter in `fit`.
*/
sample_weight?: string | boolean
}): Promise<any> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before set_fit_request()'
)
}
// set up method params
await this._py
.ex`pms_LogisticRegressionCV_set_fit_request = {'sample_weight': ${
opts['sample_weight'] ?? undefined
}}
pms_LogisticRegressionCV_set_fit_request = {k: v for k, v in pms_LogisticRegressionCV_set_fit_request.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_set_fit_request = bridgeLogisticRegressionCV[${this.id}].set_fit_request(**pms_LogisticRegressionCV_set_fit_request)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_set_fit_request.tolist() if hasattr(res_LogisticRegressionCV_set_fit_request, 'tolist') else res_LogisticRegressionCV_set_fit_request`
}
/**
Request metadata passed to the `score` method.
Note that this method is only relevant if `enable\_metadata\_routing=True` (see [`sklearn.set\_config`](sklearn.set_config.html#sklearn.set_config "sklearn.set_config")). Please see [User Guide](../../metadata_routing.html#metadata-routing) on how the routing mechanism works.
The options for each parameter are:
*/
async set_score_request(opts: {
/**
Metadata routing for `sample\_weight` parameter in `score`.
*/
sample_weight?: string | boolean
}): Promise<any> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before set_score_request()'
)
}
// set up method params
await this._py
.ex`pms_LogisticRegressionCV_set_score_request = {'sample_weight': ${
opts['sample_weight'] ?? undefined
}}
pms_LogisticRegressionCV_set_score_request = {k: v for k, v in pms_LogisticRegressionCV_set_score_request.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_set_score_request = bridgeLogisticRegressionCV[${this.id}].set_score_request(**pms_LogisticRegressionCV_set_score_request)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_set_score_request.tolist() if hasattr(res_LogisticRegressionCV_set_score_request, 'tolist') else res_LogisticRegressionCV_set_score_request`
}
/**
Convert coefficient matrix to sparse format.
Converts the `coef\_` member to a scipy.sparse matrix, which for L1-regularized models can be much more memory- and storage-efficient than the usual numpy.ndarray representation.
The `intercept\_` member is not converted.
*/
async sparsify(opts: {}): Promise<any> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error('LogisticRegressionCV must call init() before sparsify()')
}
// set up method params
await this._py.ex`pms_LogisticRegressionCV_sparsify = {}
pms_LogisticRegressionCV_sparsify = {k: v for k, v in pms_LogisticRegressionCV_sparsify.items() if v is not None}`
// invoke method
await this._py
.ex`res_LogisticRegressionCV_sparsify = bridgeLogisticRegressionCV[${this.id}].sparsify(**pms_LogisticRegressionCV_sparsify)`
// convert the result from python to node.js
return this
._py`res_LogisticRegressionCV_sparsify.tolist() if hasattr(res_LogisticRegressionCV_sparsify, 'tolist') else res_LogisticRegressionCV_sparsify`
}
/**
A list of class labels known to the classifier.
*/
get classes_(): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing classes_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_classes_ = bridgeLogisticRegressionCV[${this.id}].classes_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_classes_.tolist() if hasattr(attr_LogisticRegressionCV_classes_, 'tolist') else attr_LogisticRegressionCV_classes_`
})()
}
/**
Coefficient of the features in the decision function.
`coef\_` is of shape (1, n\_features) when the given problem is binary.
*/
get coef_(): Promise<NDArray[]> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing coef_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_coef_ = bridgeLogisticRegressionCV[${this.id}].coef_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_coef_.tolist() if hasattr(attr_LogisticRegressionCV_coef_, 'tolist') else attr_LogisticRegressionCV_coef_`
})()
}
/**
Intercept (a.k.a. bias) added to the decision function.
If `fit\_intercept` is set to `false`, the intercept is set to zero. `intercept\_` is of shape(1,) when the problem is binary.
*/
get intercept_(): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing intercept_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_intercept_ = bridgeLogisticRegressionCV[${this.id}].intercept_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_intercept_.tolist() if hasattr(attr_LogisticRegressionCV_intercept_, 'tolist') else attr_LogisticRegressionCV_intercept_`
})()
}
/**
Array of C i.e. inverse of regularization parameter values used for cross-validation.
*/
get Cs_(): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing Cs_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_Cs_ = bridgeLogisticRegressionCV[${this.id}].Cs_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_Cs_.tolist() if hasattr(attr_LogisticRegressionCV_Cs_, 'tolist') else attr_LogisticRegressionCV_Cs_`
})()
}
/**
Array of l1\_ratios used for cross-validation. If no l1\_ratio is used (i.e. penalty is not ‘elasticnet’), this is set to `\[`undefined`\]`
*/
get l1_ratios_(): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing l1_ratios_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_l1_ratios_ = bridgeLogisticRegressionCV[${this.id}].l1_ratios_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_l1_ratios_.tolist() if hasattr(attr_LogisticRegressionCV_l1_ratios_, 'tolist') else attr_LogisticRegressionCV_l1_ratios_`
})()
}
/**
dict with classes as the keys, and the path of coefficients obtained during cross-validating across each fold and then across each Cs after doing an OvR for the corresponding class as values. If the ‘multi\_class’ option is set to ‘multinomial’, then the coefs\_paths are the coefficients corresponding to each class. Each dict value has shape `(n\_folds, n\_cs, n\_features)` or `(n\_folds, n\_cs, n\_features + 1)` depending on whether the intercept is fit or not. If `penalty='elasticnet'`, the shape is `(n\_folds, n\_cs, n\_l1\_ratios\_, n\_features)` or `(n\_folds, n\_cs, n\_l1\_ratios\_, n\_features + 1)`.
*/
get coefs_paths_(): Promise<NDArray[][]> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing coefs_paths_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_coefs_paths_ = bridgeLogisticRegressionCV[${this.id}].coefs_paths_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_coefs_paths_.tolist() if hasattr(attr_LogisticRegressionCV_coefs_paths_, 'tolist') else attr_LogisticRegressionCV_coefs_paths_`
})()
}
/**
dict with classes as the keys, and the values as the grid of scores obtained during cross-validating each fold, after doing an OvR for the corresponding class. If the ‘multi\_class’ option given is ‘multinomial’ then the same scores are repeated across all classes, since this is the multinomial class. Each dict value has shape `(n\_folds, n\_cs)` or `(n\_folds, n\_cs, n\_l1\_ratios)` if `penalty='elasticnet'`.
*/
get scores_(): Promise<any> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing scores_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_scores_ = bridgeLogisticRegressionCV[${this.id}].scores_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_scores_.tolist() if hasattr(attr_LogisticRegressionCV_scores_, 'tolist') else attr_LogisticRegressionCV_scores_`
})()
}
/**
Array of C that maps to the best scores across every class. If refit is set to `false`, then for each class, the best C is the average of the C’s that correspond to the best scores for each fold. `C\_` is of shape(n\_classes,) when the problem is binary.
*/
get C_(): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing C_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_C_ = bridgeLogisticRegressionCV[${this.id}].C_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_C_.tolist() if hasattr(attr_LogisticRegressionCV_C_, 'tolist') else attr_LogisticRegressionCV_C_`
})()
}
/**
Array of l1\_ratio that maps to the best scores across every class. If refit is set to `false`, then for each class, the best l1\_ratio is the average of the l1\_ratio’s that correspond to the best scores for each fold. `l1\_ratio\_` is of shape(n\_classes,) when the problem is binary.
*/
get l1_ratio_(): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing l1_ratio_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_l1_ratio_ = bridgeLogisticRegressionCV[${this.id}].l1_ratio_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_l1_ratio_.tolist() if hasattr(attr_LogisticRegressionCV_l1_ratio_, 'tolist') else attr_LogisticRegressionCV_l1_ratio_`
})()
}
/**
Actual number of iterations for all classes, folds and Cs. In the binary or multinomial cases, the first dimension is equal to 1. If `penalty='elasticnet'`, the shape is `(n\_classes, n\_folds, n\_cs, n\_l1\_ratios)` or `(1, n\_folds, n\_cs, n\_l1\_ratios)`.
*/
get n_iter_(): Promise<NDArray[][]> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing n_iter_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_n_iter_ = bridgeLogisticRegressionCV[${this.id}].n_iter_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_n_iter_.tolist() if hasattr(attr_LogisticRegressionCV_n_iter_, 'tolist') else attr_LogisticRegressionCV_n_iter_`
})()
}
/**
Number of features seen during [fit](../../glossary.html#term-fit).
*/
get n_features_in_(): Promise<number> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing n_features_in_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_LogisticRegressionCV_n_features_in_ = bridgeLogisticRegressionCV[${this.id}].n_features_in_`
// convert the result from python to node.js
return this
._py`attr_LogisticRegressionCV_n_features_in_.tolist() if hasattr(attr_LogisticRegressionCV_n_features_in_, 'tolist') else attr_LogisticRegressionCV_n_features_in_`
})()
}
/**
Names of features seen during [fit](../../glossary.html#term-fit). Defined only when `X` has feature names that are all strings.
*/
get feature_names_in_(): Promise<NDArray> {
if (this._isDisposed) {
throw new Error(
'This LogisticRegressionCV instance has already been disposed'
)
}
if (!this._isInitialized) {
throw new Error(
'LogisticRegressionCV must call init() before accessing feature_names_in_'
)
}
return (async () => {
// invoke accessor