{ "info": { "author": "Lucas Boppre Niehues", "author_email": "lucasboppre@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Bayesian\n========\n\n**bayesan** is a small Python utility to reason about probabilities.\nIt uses a Bayesian system to extract features, crunch belief updates and\nspew likelihoods back. You can use either the high-level functions to\nclassify instances with supervised learning, or update beliefs manually\nwith the ``Bayes`` class.\n\nIf you want to simply classify and move files into the most fitting folder, run\nthis program from the command line passing the root folder path as parameter.\n \nHigh Level\n----------\n\n::\n\n from bayesian import classify, classify_file\n\n spams = [\"buy viagra\", \"dear recipient\", \"meet sexy singles\"] # etc\n genuines = [\"let's meet tomorrow\", \"remember to buy milk\"]\n message = \"remember the meeting tomorrow\"\n # Classify as \"genuine\" because of the words \"remember\" and \"tomorrow\".\n print classify(message, {'spam': spams, 'genuine': genuines})\n\n # Decides if the person with those measures is male or female.\n print classify_normal({'height': 6, 'weight': 130, 'foot size': 8},\n {'male': [{'height': 6, 'weight': 180, 'foot size': 12},\n {'height': 5.92, 'weight': 190, 'foot size': 11},\n {'height': 5.58, 'weight': 170, 'foot size': 12},\n {'height': 5.92, 'weight': 165, 'foot size': 10}],\n 'female': [{'height': 5, 'weight': 100, 'foot size': 6},\n {'height': 5.5, 'weight': 150, 'foot size': 8},\n {'height': 5.42, 'weight': 130, 'foot size': 7},\n {'height': 5.75, 'weight': 150, 'foot size': 9}]})\n\n # Classifies \"unknown_file\" as either a Python or Java file, considering\n # you have directories with examples of each language.\n print classify_file(\"unknown_file\", [\"java_files\", \"python_files\"])\n\n # Classifies every file under \"folder\" as either a Python or Java file,\n # considering you have subdirectories with examples of each language.\n print classify_folder(\"folder\")\n\nLow Level\n-------------\n\n::\n\n from bayesian import Bayes\n\n print ' -- Spam Filter --'\n # Database with number of sightings of each words in (genuine, spam)\n # emails.\n words_odds = {'buy': (5, 100), 'viagra': (1, 1000), 'meeting': (15, 2)}\n # Emails to be analyzed.\n emails = [\n \"let's schedule a meeting for tomorrow\", # 100% genuine (meeting)\n \"buy some viagra\", # 100% spam (buy, viagra)\n \"buy coffee for the meeting\", # buy x meeting, should be genuine\n ]\n\n for email in emails:\n # Start with priors of 90% chance being genuine, 10% spam.\n # Probabilities are normalized automatically.\n b = Bayes([('genuine', 90), ('spam', 10)])\n # Update probabilities, using the words in the emails as events and the\n # database of chances to figure out the change.\n b.update_from_events(email.split(), words_odds)\n # Print the email and if it's likely spam or not.\n print email[:15] + '...', b.most_likely()\n \n print ''\n\n print ' -- Spam Filter With Email Corpus -- '\n\n # Email corpus. A hundred spam emails to buy products and with the word\n # \"meeting\" thrown around. Genuine emails are about meetings and buying\n # milk.\n instances = {'spam': [\"buy viagra\", \"buy cialis\"] * 100 + [\"meeting love\"],\n 'genuine': [\"meeting tomorrow\", \"buy milk\"] * 100}\n\n # Use str.split to extract features/events/words from the corpus and build\n # the model.\n model = bayesian.extract_events_odds(instances, str.split)\n # Create a new Bayes instance with 10%/90% priors on emails being genuine.\n b = Bayes({'spam': .9, 'genuine': .1})\n # Update beliefs with features/events/words from an email.\n b.update_from_events(\"buy coffee for meeting\".split(), model)\n # Print the email and if it's likely spam or not.\n print \"'buy coffee for meeting'\", ':', b\n\n print ''\n\n print ' -- Classic Cancer Test Problem --'\n # 1% chance of having cancer.\n b = Bayes([('not cancer', 0.99), ('cancer', 0.01)])\n # Test positive, 9.6% false positives and 80% true positives\n b.update((9.6, 80))\n print b\n print 'Most likely:', b.most_likely()\n\n print ''\n\n print ' -- Are You Cheating? -- '\n results = ['heads', 'heads', 'tails', 'heads', 'heads']\n events_odds = {'heads': {'honest': .5, 'cheating': .9},\n 'tails': {'honest': .5, 'cheating': .1}}\n b = Bayes({'cheating': .5, 'honest': .5})\n b.update_from_events(results, events_odds)\n print b\n\n\n def b():\n return Bayes((0.99, 0.01), labels=['not cancer', 'cancer'])\n\n # Random equivalent examples, all achieve the same result.\n b() * (9.6, 80)\n (b() * (9.6, 80)).opposite().opposite()\n b().update({'not cancer': 9.6, 'cancer': 80})\n b().update((9.6, 80))\n b().update_from_events(['pos'], {'pos': (9.6, 80)})\n b().update_from_tests([True], [(9.6, 80)])\n Bayes([('not cancer', 0.99), ('cancer', 0.01)]) * (9.6, 80)\n Bayes({'not cancer': 0.99, 'cancer': 0.01}) * {'not cancer': 9.6,\n 'cancer': 80}", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/bayesian/", "keywords": null, "license": "LICENSE.txt", "maintainer": null, "maintainer_email": null, "name": "Bayesian", "package_url": "https://pypi.org/project/Bayesian/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Bayesian/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/bayesian/" }, "release_url": "https://pypi.org/project/Bayesian/0.3.1/", "requires_dist": null, "requires_python": null, "summary": "Library and utility module for Bayesian reasoning", "version": "0.3.1" }, "last_serial": 1091648, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "12dd64c0c18e2813becbb0b6287cc0aa", "sha256": "98ddcbb733495867448b587fb5ab8ff6128573b695fead9920fb12f6f58c0131" }, "downloads": -1, "filename": "Bayesian-0.1.0.zip", "has_sig": false, "md5_digest": "12dd64c0c18e2813becbb0b6287cc0aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8434, "upload_time": "2013-10-24T14:55:36", "url": "https://files.pythonhosted.org/packages/ca/89/5b80c421b20b4571b89d02aa0feba23885dfb230b8687d1334535c6734b6/Bayesian-0.1.0.zip" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "baf20a432000399b006e66716eee5e3b", "sha256": "818ca53b2abdc602c8614aed605a859d88d2653b23ac5fc9d27ac97a85c5c600" }, "downloads": -1, "filename": "Bayesian-0.2.0.zip", "has_sig": false, "md5_digest": "baf20a432000399b006e66716eee5e3b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5640, "upload_time": "2014-03-17T02:47:10", "url": "https://files.pythonhosted.org/packages/c1/a8/cff65e26098b00a2f45649a8be717eaa3ca08ce4fcb09507df69603a5de8/Bayesian-0.2.0.zip" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "1b290034ad886efc63c99382ff3d5a70", "sha256": "bd846591b43d976e9bc9d12b488a5538095959e2c7ba3e2741f0e8ea2d785374" }, "downloads": -1, "filename": "Bayesian-0.2.1.zip", "has_sig": false, "md5_digest": "1b290034ad886efc63c99382ff3d5a70", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8827, "upload_time": "2014-04-05T03:14:51", "url": "https://files.pythonhosted.org/packages/18/77/a06309e7f3a00d5509ec2dc68684053bb939e5d9494da30eacdad03bc460/Bayesian-0.2.1.zip" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "bc2bb51ba80b921b36b3ea5a51c679bc", "sha256": "6f2b816c674aa554fbe6d780f26a0ba224029940c54046258c4becbdc3d0ea16" }, "downloads": -1, "filename": "Bayesian-0.3.0.zip", "has_sig": false, "md5_digest": "bc2bb51ba80b921b36b3ea5a51c679bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10806, "upload_time": "2014-04-28T04:42:10", "url": "https://files.pythonhosted.org/packages/b1/e9/4e5cbb2fbe88f99d69c64a94a136bea7d2b242af60c24267a259101c0944/Bayesian-0.3.0.zip" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "d6ffb8409789dbac5cef54679d0bf205", "sha256": "19c6299733abf320c3e747df59e9d9c6c7f9ecb67d0e3453824c990a9d269c48" }, "downloads": -1, "filename": "Bayesian-0.3.1.zip", "has_sig": false, "md5_digest": "d6ffb8409789dbac5cef54679d0bf205", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13644, "upload_time": "2014-05-14T04:42:43", "url": "https://files.pythonhosted.org/packages/be/47/581dda9408add9090dd3642df8a9335e8e5bfb31a74158857d1c4984cff3/Bayesian-0.3.1.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d6ffb8409789dbac5cef54679d0bf205", "sha256": "19c6299733abf320c3e747df59e9d9c6c7f9ecb67d0e3453824c990a9d269c48" }, "downloads": -1, "filename": "Bayesian-0.3.1.zip", "has_sig": false, "md5_digest": "d6ffb8409789dbac5cef54679d0bf205", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13644, "upload_time": "2014-05-14T04:42:43", "url": "https://files.pythonhosted.org/packages/be/47/581dda9408add9090dd3642df8a9335e8e5bfb31a74158857d1c4984cff3/Bayesian-0.3.1.zip" } ] }