{"id":15038564,"url":"https://github.com/akimach/swiftnaivebayes","last_synced_at":"2025-04-09T23:41:08.345Z","repository":{"id":62456682,"uuid":"73705967","full_name":"akimach/SwiftNaiveBayes","owner":"akimach","description":"Naive Bayes classifier implemented in Swift","archived":false,"fork":false,"pushed_at":"2017-10-27T03:51:33.000Z","size":62,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T01:35:15.384Z","etag":null,"topics":["carthage","cocoapods","machine-learning","machine-learning-algorithms","naive-bayes-classifier","naivebayes","swift","swift-3","swift-language","swift-library"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akimach.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-14T13:13:56.000Z","updated_at":"2021-11-16T04:37:11.000Z","dependencies_parsed_at":"2022-11-02T00:17:05.486Z","dependency_job_id":null,"html_url":"https://github.com/akimach/SwiftNaiveBayes","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akimach%2FSwiftNaiveBayes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akimach%2FSwiftNaiveBayes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akimach%2FSwiftNaiveBayes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akimach%2FSwiftNaiveBayes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akimach","download_url":"https://codeload.github.com/akimach/SwiftNaiveBayes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131467,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["carthage","cocoapods","machine-learning","machine-learning-algorithms","naive-bayes-classifier","naivebayes","swift","swift-3","swift-language","swift-library"],"created_at":"2024-09-24T20:38:56.513Z","updated_at":"2025-04-09T23:41:08.329Z","avatar_url":"https://github.com/akimach.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"SwiftNaiveBayes\n===\n\n![](http://img.shields.io/badge/Swift-3.0-blue.svg)\n![macOS](https://img.shields.io/badge/os-macOS-green.svg?style=flat)\n![Linux](https://img.shields.io/badge/os-linux-green.svg?style=flat)\n![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)\n![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)\n![CocoaPods compatible](https://img.shields.io/badge/CocoaPods-compatible-4BC51D.svg)\n![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)\n\nNaive Bayes classifier implemented in Swift\n\n## Description\n\nImplementation of Naive Bayes Classifier algorithm in Swift3.x, supporting **Gaussian naive Bayes**, **Multinomial naive Bayes** and **Bernoulli naive Bayes**\n\n## Usage\n\nSwiftNaiveBayes is same as [Scikit learn](http://scikit-learn.org/stable/modules/naive_bayes.html)'s interface.\n\n```swift\nimport SwiftNaiveBayes\n\nlet nb = NaiveBayes()\n// Positive tokens and the frequencies [\"token A\": Frequency of token A, ...]\nlet pos = [\"computer\": 3, \"programming\": 2, \"python\": 1, \"swift\": 2]\n// Negative tokens [\"token X\": Frequency of token X, ...]\nlet neg = [\"game\": 2, \"computer\": 2, \"video\": 1, \"programming\": 1]\n// Positive tokens for testing\nlet posTest = [\"computer\": 2, \"ruby\": 1, \"swift\": 1, \"programming\": 1]\n// Train model\n// [\"Label A\": [\"token A\": Frequency of token A, ...]]\nnb.fit([\"positive\": pos, \"negative\": neg])\n// Predicts log probabilities for each label\nlet logProbs = nb.predict(posTest)\nprint(logProbs) //=\u003e [\"positive\": -8.9186205290602363, \"negative\": -10.227308671603783]\n// Use method chaining\nnb.fit([\"positive\": pos, \"negative\": neg]).predict(posTest)\n\n// Save session\ntry! nb.save(\"nb.session\")\n// Restore session\nlet nb2 = NaiveBayes(\"nb.session\")\n```\n\n## Install\n\n### Swift Package Manager\n\n`Package.swift`:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"MyApp\",\n    targets: [],\n    dependencies: [\n        .Package(url: \"https://github.com/akimach/SwiftNaiveBayes.git\", majorVersion: 1),\n    ]\n)\n```\n\n### CocoaPods\n\n`Podfile`:\n\n```\nplatform :ios, '8.0'\nuse_frameworks!\n\ntarget 'MyApp' do\n    pod 'SwiftNaiveBayes'\nend\n```\n\n### Carthage\n\n`Cartfile`:\n\n```\ngithub \"akimach/SwiftNaiveBayes\"\n```\n\n## Licence\n\n[MIT](https://github.com/akimach/SwiftNaiveBayes/blob/master/LICENSE)\n\n## Author\n\n[akimach](https://github.com/akimach)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakimach%2Fswiftnaivebayes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakimach%2Fswiftnaivebayes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakimach%2Fswiftnaivebayes/lists"}