Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Documentation
Creates learning material for the program combining
samples and their corresponding classes into
a Labeled
datatype.
:: Eq a | |
=> Material a | learning material made with |
-> String | the sample string to be classified |
-> a | a datatype representing a class to classify text |
Runs a sample string through the Naive Bayes algorithm using
training material made by makeMaterial
data Classified a Source #
A class which has a specific probability of occuring
Classified | |
|
Eq a => Eq (Classified a) Source # | |
Eq a => Ord (Classified a) Source # | |
A frequency list of words that has been assigned a class
Example: Simple Usage
In this example a list of sample reviews and their corresponding classes
are zipped into an association list to be passed into the makeMaterial
function.
This newly created material is then passed into the runBayes
function, along with
a new review. This will classify the new review based on the training material that
has been given.
data Class = Positive | Negative deriving (Eq, Show)
doc1 = "I loved the movie" doc2 = "I hated the movie" doc3 = "a great movie. good movie" doc4 = "poor acting" doc5 = "great acting. a good movie"
docs = [doc1, doc2, doc3, doc4, doc5] correspondingClasses = [Positive, Negative, Positive, Negative, Positive] classifiedDocs = zip docs correspondingClasses
main :: IO () main = do let material = makeMaterial classifiedDocs let review = "I loved the great acting" let result = runBayes material review putStrLn $ "The review '" ++ review ++ "' is " ++ show result