Giter VIP home page Giter VIP logo

swiftnaivebayes's Introduction

SwiftNaiveBayes

macOS Linux Carthage compatible Swift Package Manager compatible CocoaPods compatible MIT License

Naive Bayes classifier implemented in Swift

Description

Implementation of Naive Bayes Classifier algorithm in Swift3.x, supporting Gaussian naive Bayes, Multinomial naive Bayes and Bernoulli naive Bayes

Usage

SwiftNaiveBayes is same as Scikit learn's interface.

import SwiftNaiveBayes

let nb = NaiveBayes()
// Positive tokens and the frequencies ["token A": Frequency of token A, ...]
let pos = ["computer": 3, "programming": 2, "python": 1, "swift": 2]
// Negative tokens ["token X": Frequency of token X, ...]
let neg = ["game": 2, "computer": 2, "video": 1, "programming": 1]
// Positive tokens for testing
let posTest = ["computer": 2, "ruby": 1, "swift": 1, "programming": 1]
// Train model
// ["Label A": ["token A": Frequency of token A, ...]]
nb.fit(["positive": pos, "negative": neg])
// Predicts log probabilities for each label
let logProbs = nb.predict(posTest)
print(logProbs) //=> ["positive": -8.9186205290602363, "negative": -10.227308671603783]
// Use method chaining
nb.fit(["positive": pos, "negative": neg]).predict(posTest)

// Save session
try! nb.save("nb.session")
// Restore session
let nb2 = NaiveBayes("nb.session")

Install

Swift Package Manager

Package.swift:

import PackageDescription

let package = Package(
    name: "MyApp",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/akimach/SwiftNaiveBayes.git", majorVersion: 1),
    ]
)

CocoaPods

Podfile:

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
    pod 'SwiftNaiveBayes'
end

Carthage

Cartfile:

github "akimach/SwiftNaiveBayes"

Licence

MIT

Author

akimach

swiftnaivebayes's People

Contributors

akimach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.