-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
MLPRegressor.ts
861 lines (694 loc) · 27.8 KB
/
MLPRegressor.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
/* 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'
/**
Multi-layer Perceptron regressor.
This model optimizes the squared error using LBFGS or stochastic gradient descent.
[Python Reference](https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html)
*/
export class MLPRegressor {
id: string
opts: any
_py: PythonBridge
_isInitialized: boolean = false
_isDisposed: boolean = false
constructor(opts?: {
/**
The ith element represents the number of neurons in the ith hidden layer.
*/
hidden_layer_sizes?: any
/**
Activation function for the hidden layer.
@defaultValue `'relu'`
*/
activation?: 'identity' | 'logistic' | 'tanh' | 'relu'
/**
The solver for weight optimization.
@defaultValue `'adam'`
*/
solver?: 'lbfgs' | 'sgd' | 'adam'
/**
Strength of the L2 regularization term. The L2 regularization term is divided by the sample size when added to the loss.
@defaultValue `0.0001`
*/
alpha?: number
/**
Size of minibatches for stochastic optimizers. If the solver is ‘lbfgs’, the regressor will not use minibatch. When set to “auto”, `batch\_size=min(200, n\_samples)`.
@defaultValue `'auto'`
*/
batch_size?: number
/**
Learning rate schedule for weight updates.
@defaultValue `'constant'`
*/
learning_rate?: 'constant' | 'invscaling' | 'adaptive'
/**
The initial learning rate used. It controls the step-size in updating the weights. Only used when solver=’sgd’ or ‘adam’.
@defaultValue `0.001`
*/
learning_rate_init?: number
/**
The exponent for inverse scaling learning rate. It is used in updating effective learning rate when the learning\_rate is set to ‘invscaling’. Only used when solver=’sgd’.
@defaultValue `0.5`
*/
power_t?: number
/**
Maximum number of iterations. The solver iterates until convergence (determined by ‘tol’) or this number of iterations. For stochastic solvers (‘sgd’, ‘adam’), note that this determines the number of epochs (how many times each data point will be used), not the number of gradient steps.
@defaultValue `200`
*/
max_iter?: number
/**
Whether to shuffle samples in each iteration. Only used when solver=’sgd’ or ‘adam’.
@defaultValue `true`
*/
shuffle?: boolean
/**
Determines random number generation for weights and bias initialization, train-test split if early stopping is used, and batch sampling when solver=’sgd’ or ‘adam’. Pass an int for reproducible results across multiple function calls. See [Glossary](../../glossary.html#term-random_state).
*/
random_state?: number
/**
Tolerance for the optimization. When the loss or score is not improving by at least `tol` for `n\_iter\_no\_change` consecutive iterations, unless `learning\_rate` is set to ‘adaptive’, convergence is considered to be reached and training stops.
@defaultValue `0.0001`
*/
tol?: number
/**
Whether to print progress messages to stdout.
@defaultValue `false`
*/
verbose?: boolean
/**
When set to `true`, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. See [the Glossary](../../glossary.html#term-warm_start).
@defaultValue `false`
*/
warm_start?: boolean
/**
Momentum for gradient descent update. Should be between 0 and 1. Only used when solver=’sgd’.
@defaultValue `0.9`
*/
momentum?: number
/**
Whether to use Nesterov’s momentum. Only used when solver=’sgd’ and momentum > 0.
@defaultValue `true`
*/
nesterovs_momentum?: boolean
/**
Whether to use early stopping to terminate training when validation score is not improving. If set to `true`, it will automatically set aside `validation\_fraction` of training data as validation and terminate training when validation score is not improving by at least `tol` for `n\_iter\_no\_change` consecutive epochs. Only effective when solver=’sgd’ or ‘adam’.
@defaultValue `false`
*/
early_stopping?: boolean
/**
The proportion of training data to set aside as validation set for early stopping. Must be between 0 and 1. Only used if early\_stopping is `true`.
@defaultValue `0.1`
*/
validation_fraction?: number
/**
Exponential decay rate for estimates of first moment vector in adam, should be in \[0, 1). Only used when solver=’adam’.
@defaultValue `0.9`
*/
beta_1?: number
/**
Exponential decay rate for estimates of second moment vector in adam, should be in \[0, 1). Only used when solver=’adam’.
@defaultValue `0.999`
*/
beta_2?: number
/**
Value for numerical stability in adam. Only used when solver=’adam’.
@defaultValue `1e-8`
*/
epsilon?: number
/**
Maximum number of epochs to not meet `tol` improvement. Only effective when solver=’sgd’ or ‘adam’.
@defaultValue `10`
*/
n_iter_no_change?: number
/**
Only used when solver=’lbfgs’. Maximum number of function calls. The solver iterates until convergence (determined by `tol`), number of iterations reaches max\_iter, or this number of function calls. Note that number of function calls will be greater than or equal to the number of iterations for the MLPRegressor.
@defaultValue `15000`
*/
max_fun?: number
}) {
this.id = `MLPRegressor${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 MLPRegressor instance has already been disposed')
}
if (this._isInitialized) {
return
}
if (!py) {
throw new Error('MLPRegressor.init requires a PythonBridge instance')
}
this._py = py
await this._py.ex`
import numpy as np
from sklearn.neural_network import MLPRegressor
try: bridgeMLPRegressor
except NameError: bridgeMLPRegressor = {}
`
// set up constructor params
await this._py.ex`ctor_MLPRegressor = {'hidden_layer_sizes': np.array(${
this.opts['hidden_layer_sizes'] ?? undefined
}) if ${
this.opts['hidden_layer_sizes'] !== undefined
} else None, 'activation': ${
this.opts['activation'] ?? undefined
}, 'solver': ${this.opts['solver'] ?? undefined}, 'alpha': ${
this.opts['alpha'] ?? undefined
}, 'batch_size': ${
this.opts['batch_size'] ?? undefined
}, 'learning_rate': ${
this.opts['learning_rate'] ?? undefined
}, 'learning_rate_init': ${
this.opts['learning_rate_init'] ?? undefined
}, 'power_t': ${this.opts['power_t'] ?? undefined}, 'max_iter': ${
this.opts['max_iter'] ?? undefined
}, 'shuffle': ${this.opts['shuffle'] ?? undefined}, 'random_state': ${
this.opts['random_state'] ?? undefined
}, 'tol': ${this.opts['tol'] ?? undefined}, 'verbose': ${
this.opts['verbose'] ?? undefined
}, 'warm_start': ${this.opts['warm_start'] ?? undefined}, 'momentum': ${
this.opts['momentum'] ?? undefined
}, 'nesterovs_momentum': ${
this.opts['nesterovs_momentum'] ?? undefined
}, 'early_stopping': ${
this.opts['early_stopping'] ?? undefined
}, 'validation_fraction': ${
this.opts['validation_fraction'] ?? undefined
}, 'beta_1': ${this.opts['beta_1'] ?? undefined}, 'beta_2': ${
this.opts['beta_2'] ?? undefined
}, 'epsilon': ${this.opts['epsilon'] ?? undefined}, 'n_iter_no_change': ${
this.opts['n_iter_no_change'] ?? undefined
}, 'max_fun': ${this.opts['max_fun'] ?? undefined}}
ctor_MLPRegressor = {k: v for k, v in ctor_MLPRegressor.items() if v is not None}`
await this._py
.ex`bridgeMLPRegressor[${this.id}] = MLPRegressor(**ctor_MLPRegressor)`
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 bridgeMLPRegressor[${this.id}]`
this._isDisposed = true
}
/**
Fit the model to data matrix X and target(s) y.
*/
async fit(opts: {
/**
The input data.
*/
X?: NDArray | SparseMatrix[]
/**
The target values (class labels in classification, real numbers in regression).
*/
y?: NDArray
}): Promise<any> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error('MLPRegressor must call init() before fit()')
}
// set up method params
await this._py.ex`pms_MLPRegressor_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}
pms_MLPRegressor_fit = {k: v for k, v in pms_MLPRegressor_fit.items() if v is not None}`
// invoke method
await this._py
.ex`res_MLPRegressor_fit = bridgeMLPRegressor[${this.id}].fit(**pms_MLPRegressor_fit)`
// convert the result from python to node.js
return this
._py`res_MLPRegressor_fit.tolist() if hasattr(res_MLPRegressor_fit, 'tolist') else res_MLPRegressor_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 MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before get_metadata_routing()'
)
}
// set up method params
await this._py.ex`pms_MLPRegressor_get_metadata_routing = {'routing': ${
opts['routing'] ?? undefined
}}
pms_MLPRegressor_get_metadata_routing = {k: v for k, v in pms_MLPRegressor_get_metadata_routing.items() if v is not None}`
// invoke method
await this._py
.ex`res_MLPRegressor_get_metadata_routing = bridgeMLPRegressor[${this.id}].get_metadata_routing(**pms_MLPRegressor_get_metadata_routing)`
// convert the result from python to node.js
return this
._py`res_MLPRegressor_get_metadata_routing.tolist() if hasattr(res_MLPRegressor_get_metadata_routing, 'tolist') else res_MLPRegressor_get_metadata_routing`
}
/**
Update the model with a single iteration over the given data.
*/
async partial_fit(opts: {
/**
The input data.
*/
X?: ArrayLike | SparseMatrix[]
/**
The target values.
*/
y?: NDArray
}): Promise<any> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error('MLPRegressor must call init() before partial_fit()')
}
// set up method params
await this._py.ex`pms_MLPRegressor_partial_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}
pms_MLPRegressor_partial_fit = {k: v for k, v in pms_MLPRegressor_partial_fit.items() if v is not None}`
// invoke method
await this._py
.ex`res_MLPRegressor_partial_fit = bridgeMLPRegressor[${this.id}].partial_fit(**pms_MLPRegressor_partial_fit)`
// convert the result from python to node.js
return this
._py`res_MLPRegressor_partial_fit.tolist() if hasattr(res_MLPRegressor_partial_fit, 'tolist') else res_MLPRegressor_partial_fit`
}
/**
Predict using the multi-layer perceptron model.
*/
async predict(opts: {
/**
The input data.
*/
X?: ArrayLike | SparseMatrix[]
}): Promise<NDArray[]> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error('MLPRegressor must call init() before predict()')
}
// set up method params
await this._py.ex`pms_MLPRegressor_predict = {'X': np.array(${
opts['X'] ?? undefined
}) if ${opts['X'] !== undefined} else None}
pms_MLPRegressor_predict = {k: v for k, v in pms_MLPRegressor_predict.items() if v is not None}`
// invoke method
await this._py
.ex`res_MLPRegressor_predict = bridgeMLPRegressor[${this.id}].predict(**pms_MLPRegressor_predict)`
// convert the result from python to node.js
return this
._py`res_MLPRegressor_predict.tolist() if hasattr(res_MLPRegressor_predict, 'tolist') else res_MLPRegressor_predict`
}
/**
Return the coefficient of determination of the prediction.
The coefficient of determination \\(R^2\\) is defined as \\((1 - \\frac{u}{v})\\), where \\(u\\) is the residual sum of squares `((y\_true \- y\_pred)\*\* 2).sum()` and \\(v\\) is the total sum of squares `((y\_true \- y\_true.mean()) \*\* 2).sum()`. The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of `y`, disregarding the input features, would get a \\(R^2\\) score of 0.0.
*/
async score(opts: {
/**
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape `(n\_samples, n\_samples\_fitted)`, where `n\_samples\_fitted` is the number of samples used in the fitting for the estimator.
*/
X?: ArrayLike[]
/**
True values for `X`.
*/
y?: ArrayLike
/**
Sample weights.
*/
sample_weight?: ArrayLike
}): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error('MLPRegressor must call init() before score()')
}
// set up method params
await this._py.ex`pms_MLPRegressor_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_MLPRegressor_score = {k: v for k, v in pms_MLPRegressor_score.items() if v is not None}`
// invoke method
await this._py
.ex`res_MLPRegressor_score = bridgeMLPRegressor[${this.id}].score(**pms_MLPRegressor_score)`
// convert the result from python to node.js
return this
._py`res_MLPRegressor_score.tolist() if hasattr(res_MLPRegressor_score, 'tolist') else res_MLPRegressor_score`
}
/**
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 MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before set_score_request()'
)
}
// set up method params
await this._py.ex`pms_MLPRegressor_set_score_request = {'sample_weight': ${
opts['sample_weight'] ?? undefined
}}
pms_MLPRegressor_set_score_request = {k: v for k, v in pms_MLPRegressor_set_score_request.items() if v is not None}`
// invoke method
await this._py
.ex`res_MLPRegressor_set_score_request = bridgeMLPRegressor[${this.id}].set_score_request(**pms_MLPRegressor_set_score_request)`
// convert the result from python to node.js
return this
._py`res_MLPRegressor_set_score_request.tolist() if hasattr(res_MLPRegressor_set_score_request, 'tolist') else res_MLPRegressor_set_score_request`
}
/**
The current loss computed with the loss function.
*/
get loss_(): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error('MLPRegressor must call init() before accessing loss_')
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_loss_ = bridgeMLPRegressor[${this.id}].loss_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_loss_.tolist() if hasattr(attr_MLPRegressor_loss_, 'tolist') else attr_MLPRegressor_loss_`
})()
}
/**
The minimum loss reached by the solver throughout fitting. If `early\_stopping=True`, this attribute is set to `undefined`. Refer to the `best\_validation\_score\_` fitted attribute instead. Only accessible when solver=’sgd’ or ‘adam’.
*/
get best_loss_(): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing best_loss_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_best_loss_ = bridgeMLPRegressor[${this.id}].best_loss_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_best_loss_.tolist() if hasattr(attr_MLPRegressor_best_loss_, 'tolist') else attr_MLPRegressor_best_loss_`
})()
}
/**
Loss value evaluated at the end of each training step. The ith element in the list represents the loss at the ith iteration. Only accessible when solver=’sgd’ or ‘adam’.
*/
get loss_curve_(): Promise<any[]> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing loss_curve_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_loss_curve_ = bridgeMLPRegressor[${this.id}].loss_curve_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_loss_curve_.tolist() if hasattr(attr_MLPRegressor_loss_curve_, 'tolist') else attr_MLPRegressor_loss_curve_`
})()
}
/**
The score at each iteration on a held-out validation set. The score reported is the R2 score. Only available if `early\_stopping=True`, otherwise the attribute is set to `undefined`. Only accessible when solver=’sgd’ or ‘adam’.
*/
get validation_scores_(): Promise<any[]> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing validation_scores_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_validation_scores_ = bridgeMLPRegressor[${this.id}].validation_scores_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_validation_scores_.tolist() if hasattr(attr_MLPRegressor_validation_scores_, 'tolist') else attr_MLPRegressor_validation_scores_`
})()
}
/**
The best validation score (i.e. R2 score) that triggered the early stopping. Only available if `early\_stopping=True`, otherwise the attribute is set to `undefined`. Only accessible when solver=’sgd’ or ‘adam’.
*/
get best_validation_score_(): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing best_validation_score_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_best_validation_score_ = bridgeMLPRegressor[${this.id}].best_validation_score_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_best_validation_score_.tolist() if hasattr(attr_MLPRegressor_best_validation_score_, 'tolist') else attr_MLPRegressor_best_validation_score_`
})()
}
/**
The number of training samples seen by the solver during fitting. Mathematically equals `n\_iters \* X.shape\[0\]`, it means `time\_step` and it is used by optimizer’s learning rate scheduler.
*/
get t_(): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error('MLPRegressor must call init() before accessing t_')
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_t_ = bridgeMLPRegressor[${this.id}].t_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_t_.tolist() if hasattr(attr_MLPRegressor_t_, 'tolist') else attr_MLPRegressor_t_`
})()
}
/**
The ith element in the list represents the weight matrix corresponding to layer i.
*/
get coefs_(): Promise<any[]> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error('MLPRegressor must call init() before accessing coefs_')
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_coefs_ = bridgeMLPRegressor[${this.id}].coefs_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_coefs_.tolist() if hasattr(attr_MLPRegressor_coefs_, 'tolist') else attr_MLPRegressor_coefs_`
})()
}
/**
The ith element in the list represents the bias vector corresponding to layer i + 1.
*/
get intercepts_(): Promise<any[]> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing intercepts_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_intercepts_ = bridgeMLPRegressor[${this.id}].intercepts_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_intercepts_.tolist() if hasattr(attr_MLPRegressor_intercepts_, 'tolist') else attr_MLPRegressor_intercepts_`
})()
}
/**
Number of features seen during [fit](../../glossary.html#term-fit).
*/
get n_features_in_(): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing n_features_in_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_n_features_in_ = bridgeMLPRegressor[${this.id}].n_features_in_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_n_features_in_.tolist() if hasattr(attr_MLPRegressor_n_features_in_, 'tolist') else attr_MLPRegressor_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 MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing feature_names_in_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_feature_names_in_ = bridgeMLPRegressor[${this.id}].feature_names_in_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_feature_names_in_.tolist() if hasattr(attr_MLPRegressor_feature_names_in_, 'tolist') else attr_MLPRegressor_feature_names_in_`
})()
}
/**
The number of iterations the solver has run.
*/
get n_iter_(): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error('MLPRegressor must call init() before accessing n_iter_')
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_n_iter_ = bridgeMLPRegressor[${this.id}].n_iter_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_n_iter_.tolist() if hasattr(attr_MLPRegressor_n_iter_, 'tolist') else attr_MLPRegressor_n_iter_`
})()
}
/**
Number of layers.
*/
get n_layers_(): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing n_layers_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_n_layers_ = bridgeMLPRegressor[${this.id}].n_layers_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_n_layers_.tolist() if hasattr(attr_MLPRegressor_n_layers_, 'tolist') else attr_MLPRegressor_n_layers_`
})()
}
/**
Number of outputs.
*/
get n_outputs_(): Promise<number> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing n_outputs_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_n_outputs_ = bridgeMLPRegressor[${this.id}].n_outputs_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_n_outputs_.tolist() if hasattr(attr_MLPRegressor_n_outputs_, 'tolist') else attr_MLPRegressor_n_outputs_`
})()
}
/**
Name of the output activation function.
*/
get out_activation_(): Promise<string> {
if (this._isDisposed) {
throw new Error('This MLPRegressor instance has already been disposed')
}
if (!this._isInitialized) {
throw new Error(
'MLPRegressor must call init() before accessing out_activation_'
)
}
return (async () => {
// invoke accessor
await this._py
.ex`attr_MLPRegressor_out_activation_ = bridgeMLPRegressor[${this.id}].out_activation_`
// convert the result from python to node.js
return this
._py`attr_MLPRegressor_out_activation_.tolist() if hasattr(attr_MLPRegressor_out_activation_, 'tolist') else attr_MLPRegressor_out_activation_`
})()
}
}