Back to godoc.org
github.com/pa-m/sklearn / naive_bayes

Package naivebayes

v0.0.0-...-beb861e
Latest Go to latest

The latest major version is .

Published: Jul 11, 2020 | License: MIT | Module: github.com/pa-m/sklearn

Index

Examples

type BaseNB

type BaseNB struct {
	Classes []float64
	// contains filtered or unexported fields
}

BaseNB is the abstract base class for naive Bayes estimators

func (*BaseNB) GetNOutputs

func (m *BaseNB) GetNOutputs() int

GetNOutputs ...

func (*BaseNB) Predict

func (m *BaseNB) Predict(X mat.Matrix, Y mat.Mutable) *mat.Dense

Predict perform classification on an array of test vectors X

func (*BaseNB) PredictLogProbas

func (m *BaseNB) PredictLogProbas(Xmatrix mat.Matrix, Ymutable mat.Mutable) *mat.Dense

PredictLogProbas return log-probability estimates.

func (*BaseNB) PredictProbas

func (m *BaseNB) PredictProbas(Xmatrix mat.Matrix, Ymutable mat.Mutable) *mat.Dense

PredictProbas return log-probability estimates.

func (*BaseNB) Score

func (m *BaseNB) Score(X, Y mat.Matrix) float64

Score returns AccuracyScore

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

Code:

//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)
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) IsClassifier

func (m *GaussianNB) IsClassifier() bool

IsClassifier ...

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier