{"id":31831264,"url":"https://github.com/raphaelsty/abayes","last_synced_at":"2025-10-11T21:48:56.717Z","repository":{"id":49756495,"uuid":"293875804","full_name":"raphaelsty/abayes","owner":"raphaelsty","description":"Autoregressive Bayesian linear model","archived":false,"fork":false,"pushed_at":"2020-09-10T01:15:52.000Z","size":181,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-08T19:23:54.383Z","etag":null,"topics":["autoregressive","bayes","bayesian","bayesian-inference","linear-regression","machine-learning","online"],"latest_commit_sha":null,"homepage":"","language":"Python","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/raphaelsty.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":"2020-09-08T17:07:06.000Z","updated_at":"2024-01-04T16:50:07.000Z","dependencies_parsed_at":"2022-09-07T07:51:43.982Z","dependency_job_id":null,"html_url":"https://github.com/raphaelsty/abayes","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/raphaelsty/abayes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelsty%2Fabayes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelsty%2Fabayes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelsty%2Fabayes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelsty%2Fabayes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raphaelsty","download_url":"https://codeload.github.com/raphaelsty/abayes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raphaelsty%2Fabayes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008824,"owners_count":26084518,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["autoregressive","bayes","bayesian","bayesian-inference","linear-regression","machine-learning","online"],"created_at":"2025-10-11T21:48:52.274Z","updated_at":"2025-10-11T21:48:56.710Z","avatar_url":"https://github.com/raphaelsty.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eOnline autoregressive bayesian linear regression\u003c/h1\u003e\n\u003c/div\u003e\n\u003c/br\u003e\n\nThis minimalist tool is dedicated to the bayesian linear regression implemented by **[Max Halford](https://github.com/MaxHalford)** in his blog post **[Bayesian linear regression for practitioners](https://maxhalford.github.io/blog/bayesian-linear-regression/)**. I slightly modified the code to obtain an autoregressive version of the original model.\n\n**For the time being, the model will systematically assume that the residues follow a normal distribution. It will be necessary to wait for the next updates of the library to include new distributions.**\n\nBayesian linear regression has many advantages. It allows to measure the **uncertainty** of the model and to build **confidence intervals**. The simplicity of this model and its ability to answer \"I don't know\" makes it practical and adapted to many **concrete problems**.\n\nIts online autoregressive counterpart is a nice tool for the toolbox of programmers, hackers and practitioners.\n\n#### Installation:\n\n```\npip install git+https://github.com/raphaelsty/abayes\n```\n\n#### Example:\n\nLet's try to predict my ice cream consumption. I have created a dummy dataset where I record my ice cream consumption for each month of the year and for 3 years.\n\n```python3\nfrom abayes import dataset\ndf = dataset.LoadIceCream()\ndf.head()\n```\n\n\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"src/table.png\" alt=\"drawing\" width=\"100\"/\u003e\n\n\u003c/div\u003e\n\u003cbr\u003e\n\nWe initialise the auto-regressive model with a periodicity of 24. We will use the years n-1 and n-2 to predict my ice consumption in year n.\n\n```python3\nfrom abayes import linear\n\nmodel = linear.AbayesLr(\n    p     = 24,\n    alpha = 0.3,\n    beta  = 1.,\n)\n\nmodel.learn(df['y'].values)\n\nforecast = model.forecast(12)\n\nlower_bound, upper_bound = model.forecast_interval(12, alpha = 0.90)\n```\n\n\u003cdetails\u003e\u003csummary\u003eplot\u003c/summary\u003e\n\n```python3\nimport matplotlib.pyplot as plt\n\n%config InlineBackend.figure_format = 'retina'\n\nrange_train    = range(len(df['y']))\nrange_forecast = range(len(df['y']), len(df['y']) + len(forecast))\n\nfig, ax = plt.subplots(figsize=(15, 6))\n\nax.plot(range_train, df['y'], color='deepskyblue', label ='train')\n\nax.plot(range_forecast, forecast, color='red', linestyle='--', label ='forecast')\n\nax.fill_between(\n    x     = range_forecast,\n    y1    = lower_bound,\n    y2    = upper_bound,\n    alpha = 0.1,\n    color = 'red',\n    label = 'confidence'\n)\n\nplt.xticks(\n    range(len(df['y']) + len(forecast)), \n    df['time'].tolist() + [f\"2020/{'%02d' % i}\" for i in range(1, 13)], \n    rotation='vertical'\n)\n\nax.set_title('Quantity of ice cream')\n\nax.set_xlabel('Period')\n\nax.set_ylabel('Quantity')\n\nax.legend()\n\nplt.show()\n```\n\n\u003c/details\u003e\n\n![](src/chart.png)\n\n**The model can also learn by mini-batch.**\n\n```python3\nimport numpy as np\n\nfrom abayes import linear\n\nmodel = linear.AbayesLr(\n    p     = 24,\n    alpha = 0.3,\n    beta  = 1,\n)\n\nfor time, y in enumerate(df['y'].values):\n    \n    # Online autoregressive model needs to store enough data to make a prediction (\u003e period).\n    if time \u003e 24:\n        \n        lower_bound, upper_bound = model.forecast_interval(1, alpha = 0.9)\n        y_pred = model.forecast(1)\n        \n        print('\\n')\n        print(f'time: {time}')\n        print(f'\\t y: {y}')\n        print(f'\\t Most likely value: {y_pred[0]:6f}')\n        print(f'\\t Confidence interval: [{lower_bound[0]:6f} ; {upper_bound[0]:6f}]')\n    \n    model.learn(np.array([y]))\n```\n\n```\ntime: 25\n\t y: 46\n\t Most likely value: 16.066921\n\t Confidence interval: [-231.651593 ; 263.785435]\n\n\ntime: 26\n\t y: 27\n\t Most likely value: 50.016886\n\t Confidence interval: [-179.828306 ; 279.862078]\n\n\ntime: 27\n\t y: 30\n\t Most likely value: 16.442225\n\t Confidence interval: [-214.224545 ; 247.108994]\n\n\ntime: 28\n\t y: 101\n\t Most likely value: 21.766659\n\t Confidence interval: [-205.891318 ; 249.424635]\n\n\ntime: 29\n\t y: 135\n\t Most likely value: 106.731389\n\t Confidence interval: [-124.906692 ; 338.369470]\n\n\ntime: 30\n\t y: 250\n\t Most likely value: 143.074596\n\t Confidence interval: [-75.066693 ; 361.215885]\n\n\ntime: 31\n\t y: 210\n\t Most likely value: 231.908803\n\t Confidence interval: [38.905614 ; 424.911993]\n\n\ntime: 32\n\t y: 127\n\t Most likely value: 165.226916\n\t Confidence interval: [-17.324602 ; 347.778435]\n\n\ntime: 33\n\t y: 50\n\t Most likely value: 78.684325\n\t Confidence interval: [-75.679416 ; 233.048066]\n\n\ntime: 34\n\t y: 14\n\t Most likely value: -14.522046\n\t Confidence interval: [-157.498855 ; 128.454763]\n\n\ntime: 35\n\t y: 56\n\t Most likely value: 52.063575\n\t Confidence interval: [-50.776582 ; 154.903732]\n```\n\n#### License\n\nThis project is free and open-source software licensed under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphaelsty%2Fabayes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraphaelsty%2Fabayes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraphaelsty%2Fabayes/lists"}