bayesian

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Explanation

type Explanation struct {
	IsSpam            bool                // Final classification
	Probability       float64             // Overall spam probability
	PriorSpamProb     float64             // Prior probability of spam
	PriorHamProb      float64             // Prior probability of ham
	Details           []ExplanationDetail // Per-character probability details
	TopSpamIndicators []string            // Characters that most strongly indicate spam
	TopHamIndicators  []string            // Characters that most strongly indicate ham
}

Explanation contains the detailed explanation of why input was classified as spam or not

type ExplanationDetail

type ExplanationDetail struct {
	Char            string  // The character being analyzed
	SpamProbability float64 // Probability of this character appearing in spam
	Contribution    float64 // How much this character contributed to the final score
}

ExplanationDetail contains the probability details for a single character

type Model

type Model struct {
	WordProbs map[string]float64 // Probability of word appearing in spam
	SpamCount int                // Number of spam documents seen
	HamCount  int                // Number of ham (non-spam) documents seen
	// contains filtered or unexported fields
}

Model represents a Bayesian filter model for spam detection

func LoadModel

func LoadModel(filename string) (*Model, error)

LoadModel loads a trained model from a file

func NewModel

func NewModel() *Model

NewModel creates a new Bayesian filter model

func (*Model) Explain

func (m *Model) Explain(input []string) (*Explanation, error)

Explain provides a detailed explanation of why the input was classified as spam or not

func (*Model) IsSpam

func (m *Model) IsSpam(input []string) (bool, float64)

IsSpam checks if the input is spam and returns the probability

func (*Model) SaveModel

func (m *Model) SaveModel(filename string) error

SaveModel saves the trained model to a file

func (*Model) Train

func (m *Model) Train(input []string, isSpam bool)

Train trains the model with the given input and classification

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL