Class: GaussianNB
Gaussian Naive Bayes (GaussianNB).
Can perform online updates to model parameters via partial_fit
. For details on algorithm used to update feature means and variance online, see Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:
Constructors
new GaussianNB()
new GaussianNB(
opts
?):GaussianNB
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.priors ? | ArrayLike | Prior probabilities of the classes. If specified, the priors are not adjusted according to the data. |
opts.var_smoothing ? | number | Portion of the largest variance of all features that is added to variances for calculation stability. |
Returns GaussianNB
Defined in generated/naive_bayes/GaussianNB.ts:23
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/naive_bayes/GaussianNB.ts:21 |
_isInitialized | boolean | false | generated/naive_bayes/GaussianNB.ts:20 |
_py | PythonBridge | undefined | generated/naive_bayes/GaussianNB.ts:19 |
id | string | undefined | generated/naive_bayes/GaussianNB.ts:16 |
opts | any | undefined | generated/naive_bayes/GaussianNB.ts:17 |
Accessors
class_count_
Get Signature
get class_count_():
Promise
<ArrayLike
>
number of training samples observed in each class.
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/GaussianNB.ts:533
class_prior_
Get Signature
get class_prior_():
Promise
<ArrayLike
>
probability of each class.
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/GaussianNB.ts:558
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
class labels known to the classifier.
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/GaussianNB.ts:583
epsilon_
Get Signature
get epsilon_():
Promise
<number
>
absolute additive value to variances.
Returns Promise
<number
>
Defined in generated/naive_bayes/GaussianNB.ts:606
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/GaussianNB.ts:654
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/naive_bayes/GaussianNB.ts:629
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/naive_bayes/GaussianNB.ts:40
theta_
Get Signature
get theta_():
Promise
<ArrayLike
[]>
mean of each feature per class.
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/GaussianNB.ts:702
var_
Get Signature
get var_():
Promise
<ArrayLike
[]>
Variance of each feature per class.
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/GaussianNB.ts:679
Methods
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/naive_bayes/GaussianNB.ts:92
fit()
fit(
opts
):Promise
<any
>
Fit Gaussian Naive Bayes according to X, y.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Weights applied to individual samples (1. for unweighted). |
opts.X ? | ArrayLike [] | Training vectors, where n_samples is the number of samples and n_features is the number of features. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/naive_bayes/GaussianNB.ts:109
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/naive_bayes/GaussianNB.ts:153
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/naive_bayes/GaussianNB.ts:53
partial_fit()
partial_fit(
opts
):Promise
<any
>
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance and numerical stability overhead, hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.classes ? | ArrayLike | List of all the classes that can possibly appear in the y vector. Must be provided at the first call to partial_fit, can be omitted in subsequent calls. |
opts.sample_weight ? | ArrayLike | Weights applied to individual samples (1. for unweighted). |
opts.X ? | ArrayLike [] | Training vectors, where n_samples is the number of samples and n_features is the number of features. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/naive_bayes/GaussianNB.ts:193
predict()
predict(
opts
):Promise
<ArrayLike
>
Perform classification on an array of test vectors X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
>
Defined in generated/naive_bayes/GaussianNB.ts:242
predict_joint_log_proba()
predict_joint_log_proba(
opts
):Promise
<ArrayLike
[]>
Return joint log probability estimates for the test vector X.
For each row x of X and class y, the joint log probability is given by log P(x, y) \= log P(y) + log P(x|y),
where log P(y)
is the class prior probability and log P(x|y)
is the class-conditional probability.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/GaussianNB.ts:276
predict_log_proba()
predict_log_proba(
opts
):Promise
<ArrayLike
[]>
Return log-probability estimates for the test vector X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/GaussianNB.ts:310
predict_proba()
predict_proba(
opts
):Promise
<ArrayLike
[]>
Return probability estimates for the test vector X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
[]>
Defined in generated/naive_bayes/GaussianNB.ts:342
score()
score(
opts
):Promise
<number
>
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True labels for X . |
Returns Promise
<number
>
Defined in generated/naive_bayes/GaussianNB.ts:376
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/naive_bayes/GaussianNB.ts:422
set_partial_fit_request()
set_partial_fit_request(
opts
):Promise
<any
>
Request metadata passed to the partial_fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.classes ? | string | boolean | Metadata routing for classes parameter in partial_fit . |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in partial_fit . |
Returns Promise
<any
>
Defined in generated/naive_bayes/GaussianNB.ts:458
set_score_request()
set_score_request(
opts
):Promise
<any
>
Request metadata passed to the score
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/naive_bayes/GaussianNB.ts:501