Documentation ¶
Index ¶
- type BaseNB
- func (m *BaseNB) GetNOutputs() int
- func (m *BaseNB) Predict(X mat.Matrix, Y mat.Mutable) *mat.Dense
- func (m *BaseNB) PredictLogProbas(Xmatrix mat.Matrix, Ymutable mat.Mutable) *mat.Dense
- func (m *BaseNB) PredictProbas(Xmatrix mat.Matrix, Ymutable mat.Mutable) *mat.Dense
- func (m *BaseNB) Score(X, Y mat.Matrix) float64
- type GaussianNB
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseNB ¶
type BaseNB struct { Classes []float64 // contains filtered or unexported fields }
BaseNB is the abstract base class for naive Bayes estimators
func (*BaseNB) PredictLogProbas ¶
PredictLogProbas return log-probability estimates.
func (*BaseNB) PredictProbas ¶
PredictProbas return log-probability estimates.
type GaussianNB ¶
type GaussianNB struct { Priors []float64 VarSmoothing float64 ClassPrior []float64 ClassCount []float64 Theta *mat.Dense Sigma *mat.Dense Epsilon float64 SampleWeight []float64 BaseNB }
GaussianNB is Gaussian Naive Bayes (GaussianNB) Can perform online updates to model parameters via `partial_fit` method. 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: http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf Read more in the :ref:`User Guide <gaussian_naive_bayes>`.
Example ¶
//inspired from https://scikit-learn.org/stable/auto_examples/preprocessing/plot_scaling_importance.html //results have a small diff from python ones because train_test_split is different features, target := datasets.LoadWine().GetXY() RandomState := uint64(42) Xtrain, Xtest, Ytrain, Ytest := modelselection.TrainTestSplit(features, target, .30, RandomState) std := preprocessing.NewStandardScaler() pca := preprocessing.NewPCA() pca.NComponents = 2 gnb := NewGaussianNB(nil, 1e-9) unscaledClf := pipeline.MakePipeline(pca, gnb) unscaledClf.Fit(Xtrain, Ytrain) fmt.Printf("Prediction accuracy for the normal test dataset with PCA %.2f %%\n", 100*unscaledClf.Score(Xtest, Ytest)) std = preprocessing.NewStandardScaler() pca = preprocessing.NewPCA() pca.NComponents = 2 gnb = NewGaussianNB(nil, 1e-9) clf := pipeline.MakePipeline(std, pca, gnb) clf.Fit(Xtrain, Ytrain) score := clf.Score(Xtest, Ytest) fmt.Printf("Prediction accuracy for the standardized test dataset with PCA %.2f %%\n", 100*score)
Output: Prediction accuracy for the normal test dataset with PCA 70.37 % Prediction accuracy for the standardized test dataset with PCA 98.15 %
func NewGaussianNB ¶
func NewGaussianNB(priors []float64, varSmoothing float64) *GaussianNB
NewGaussianNB ... see GaussianNB
func (*GaussianNB) Fit ¶
func (m *GaussianNB) Fit(X, Y mat.Matrix) base.Fiter
Fit fit Gaussian Naive Bayes according to X, y
func (*GaussianNB) PartialFit ¶
func (m *GaussianNB) PartialFit(X, Y mat.Matrix, classes []float64, refit bool, sampleWeight []float64) base.Fiter
PartialFit fit Gaussian Naive Bayes according to X, y
func (*GaussianNB) PredicterClone ¶
func (m *GaussianNB) PredicterClone() base.Predicter
PredicterClone return a cloned GaussianNB as base.Predicter