{"id":13569967,"url":"https://github.com/Nixtla/mlforecast","last_synced_at":"2025-04-04T06:31:34.883Z","repository":{"id":39500939,"uuid":"361892304","full_name":"Nixtla/mlforecast","owner":"Nixtla","description":"Scalable machine 🤖 learning for time series forecasting.","archived":false,"fork":false,"pushed_at":"2025-03-17T09:12:54.000Z","size":31251,"stargazers_count":998,"open_issues_count":20,"forks_count":96,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-31T01:30:07.694Z","etag":null,"topics":["dask","forecast","forecasting","lightgbm","machine-learning","python","time-series","xgboost"],"latest_commit_sha":null,"homepage":"https://nixtlaverse.nixtla.io/mlforecast","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nixtla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-26T20:58:42.000Z","updated_at":"2025-03-30T15:37:50.000Z","dependencies_parsed_at":"2023-10-17T04:41:30.354Z","dependency_job_id":"eaab50b4-80d0-4870-92b6-911a79628c35","html_url":"https://github.com/Nixtla/mlforecast","commit_stats":{"total_commits":146,"total_committers":6,"mean_commits":"24.333333333333332","dds":0.4246575342465754,"last_synced_commit":"b621cc4d1392a36bfeedb22042aa7da22e5e69e8"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nixtla%2Fmlforecast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nixtla%2Fmlforecast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nixtla%2Fmlforecast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nixtla%2Fmlforecast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nixtla","download_url":"https://codeload.github.com/Nixtla/mlforecast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247134442,"owners_count":20889398,"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":["dask","forecast","forecasting","lightgbm","machine-learning","python","time-series","xgboost"],"created_at":"2024-08-01T14:00:46.557Z","updated_at":"2025-04-04T06:31:29.868Z","avatar_url":"https://github.com/Nixtla.png","language":"Python","readme":"# mlforecast\n[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Statistical%20Forecasting%20Algorithms%20by%20Nixtla%20\u0026url=https://github.com/Nixtla/statsforecast\u0026via=nixtlainc\u0026hashtags=StatisticalModels,TimeSeries,Forecasting)\n[![Slack](https://img.shields.io/badge/Slack-4A154B?\u0026logo=slack\u0026logoColor=white.png)](https://join.slack.com/t/nixtlacommunity/shared_invite/zt-1pmhan9j5-F54XR20edHk0UtYAPcW4KQ)\n\n\u003c!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! --\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n\u003ccenter\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/Nixtla/mlforecast/main/nbs/figs/logo.png\" /\u003e\n\u003c/center\u003e\n\u003ch1 align=\"center\"\u003e\nMachine Learning 🤖 Forecast\n\u003c/h1\u003e\n\u003ch3 align=\"center\"\u003e\nScalable machine learning for time series forecasting\n\u003c/h3\u003e\n\n[![CI](https://github.com/Nixtla/mlforecast/actions/workflows/ci.yaml/badge.svg)](https://github.com/Nixtla/mlforecast/actions/workflows/ci.yaml)\n[![Python](https://img.shields.io/pypi/pyversions/mlforecast.png)](https://pypi.org/project/mlforecast/)\n[![PyPi](https://img.shields.io/pypi/v/mlforecast?color=blue.png)](https://pypi.org/project/mlforecast/)\n[![conda-forge](https://img.shields.io/conda/vn/conda-forge/mlforecast?color=blue.png)](https://anaconda.org/conda-forge/mlforecast)\n[![License](https://img.shields.io/github/license/Nixtla/mlforecast.png)](https://github.com/Nixtla/mlforecast/blob/main/LICENSE)\n\n**mlforecast** is a framework to perform time series forecasting using\nmachine learning models, with the option to scale to massive amounts of\ndata using remote clusters.\n\n\u003c/div\u003e\n\n## Install\n\n### PyPI\n\n`pip install mlforecast`\n\n### conda-forge\n\n`conda install -c conda-forge mlforecast`\n\nFor more detailed instructions you can refer to the [installation\npage](https://nixtla.github.io/mlforecast/docs/getting-started/install.html).\n\n## Quick Start\n\n**Get Started with this [quick\nguide](https://nixtla.github.io/mlforecast/docs/getting-started/quick_start_local.html).**\n\n**Follow this [end-to-end\nwalkthrough](https://nixtla.github.io/mlforecast/docs/getting-started/end_to_end_walkthrough.html)\nfor best practices.**\n\n### Sample notebooks\n\n- [m5](https://www.kaggle.com/code/lemuz90/m5-mlforecast-eval)\n- [m5-polars](https://www.kaggle.com/code/lemuz90/m5-mlforecast-eval-polars)\n- [m4](https://www.kaggle.com/code/lemuz90/m4-competition)\n- [m4-cv](https://www.kaggle.com/code/lemuz90/m4-competition-cv)\n- [favorita](https://www.kaggle.com/code/lemuz90/mlforecast-favorita)\n\n## Why?\n\nCurrent Python alternatives for machine learning models are slow,\ninaccurate and don’t scale well. So we created a library that can be\nused to forecast in production environments.\n[`MLForecast`](https://Nixtla.github.io/mlforecast/forecast.html#mlforecast)\nincludes efficient feature engineering to train any machine learning\nmodel (with `fit` and `predict` methods such as\n[`sklearn`](https://scikit-learn.org/stable/)) to fit millions of time\nseries.\n\n## Features\n\n- Fastest implementations of feature engineering for time series\n  forecasting in Python.\n- Out-of-the-box compatibility with pandas, polars, spark, dask, and\n  ray.\n- Probabilistic Forecasting with Conformal Prediction.\n- Support for exogenous variables and static covariates.\n- Familiar `sklearn` syntax: `.fit` and `.predict`.\n\nMissing something? Please open an issue or write us in\n[![Slack](https://img.shields.io/badge/Slack-4A154B?\u0026logo=slack\u0026logoColor=white.png)](https://join.slack.com/t/nixtlaworkspace/shared_invite/zt-135dssye9-fWTzMpv2WBthq8NK0Yvu6A)\n\n## Examples and Guides\n\n📚 [End to End\nWalkthrough](https://nixtla.github.io/mlforecast/docs/getting-started/end_to_end_walkthrough.html):\nmodel training, evaluation and selection for multiple time series.\n\n🔎 [Probabilistic\nForecasting](https://nixtla.github.io/mlforecast/docs/how-to-guides/prediction_intervals.html):\nuse Conformal Prediction to produce prediciton intervals.\n\n👩‍🔬 [Cross\nValidation](https://nixtla.github.io/mlforecast/docs/how-to-guides/cross_validation.html):\nrobust model’s performance evaluation.\n\n🔌 [Predict Demand\nPeaks](https://nixtla.github.io/mlforecast/docs/tutorials/electricity_peak_forecasting.html):\nelectricity load forecasting for detecting daily peaks and reducing\nelectric bills.\n\n📈 [Transfer\nLearning](https://nixtla.github.io/mlforecast/docs/how-to-guides/transfer_learning.html):\npretrain a model using a set of time series and then predict another one\nusing that pretrained model.\n\n🌡️ [Distributed\nTraining](https://nixtla.github.io/mlforecast/docs/getting-started/quick_start_distributed.html):\nuse a Dask, Ray or Spark cluster to train models at scale.\n\n## How to use\n\nThe following provides a very basic overview, for a more detailed\ndescription see the\n[documentation](https://nixtla.github.io/mlforecast/).\n\n### Data setup\n\nStore your time series in a pandas dataframe in long format, that is,\neach row represents an observation for a specific serie and timestamp.\n\n``` python\nfrom mlforecast.utils import generate_daily_series\n\nseries = generate_daily_series(\n    n_series=20,\n    max_length=100,\n    n_static_features=1,\n    static_as_categorical=False,\n    with_trend=True\n)\nseries.head()\n```\n\n\u003cdiv\u003e\n\n|     | unique_id | ds         | y          | static_0 |\n|-----|-----------|------------|------------|----------|\n| 0   | id_00     | 2000-01-01 | 17.519167  | 72       |\n| 1   | id_00     | 2000-01-02 | 87.799695  | 72       |\n| 2   | id_00     | 2000-01-03 | 177.442975 | 72       |\n| 3   | id_00     | 2000-01-04 | 232.704110 | 72       |\n| 4   | id_00     | 2000-01-05 | 317.510474 | 72       |\n\n\u003c/div\u003e\n\n\u003e Note: The unique_id serves as an identifier for each distinct time\n\u003e series in your dataset. If you are using only single time series from\n\u003e your dataset, set this column to a constant value.\n\n### Models\n\nNext define your models, each one will be trained on all series. These\ncan be any regressor that follows the scikit-learn API.\n\n``` python\nimport lightgbm as lgb\nfrom sklearn.linear_model import LinearRegression\n```\n\n``` python\nmodels = [\n    lgb.LGBMRegressor(random_state=0, verbosity=-1),\n    LinearRegression(),\n]\n```\n\n### Forecast object\n\nNow instantiate an\n[`MLForecast`](https://Nixtla.github.io/mlforecast/forecast.html#mlforecast)\nobject with the models and the features that you want to use. The\nfeatures can be lags, transformations on the lags and date features. You\ncan also define transformations to apply to the target before fitting,\nwhich will be restored when predicting.\n\n``` python\nfrom mlforecast import MLForecast\nfrom mlforecast.lag_transforms import ExpandingMean, RollingMean\nfrom mlforecast.target_transforms import Differences\n```\n\n``` python\nfcst = MLForecast(\n    models=models,\n    freq='D',\n    lags=[7, 14],\n    lag_transforms={\n        1: [ExpandingMean()],\n        7: [RollingMean(window_size=28)]\n    },\n    date_features=['dayofweek'],\n    target_transforms=[Differences([1])],\n)\n```\n\n### Training\n\nTo compute the features and train the models call `fit` on your\n`Forecast` object.\n\n``` python\nfcst.fit(series)\n```\n\n    MLForecast(models=[LGBMRegressor, LinearRegression], freq=D, lag_features=['lag7', 'lag14', 'expanding_mean_lag1', 'rolling_mean_lag7_window_size28'], date_features=['dayofweek'], num_threads=1)\n\n### Predicting\n\nTo get the forecasts for the next `n` days call `predict(n)` on the\nforecast object. This will automatically handle the updates required by\nthe features using a recursive strategy.\n\n``` python\npredictions = fcst.predict(14)\npredictions\n```\n\n\u003cdiv\u003e\n\n|     | unique_id | ds         | LGBMRegressor | LinearRegression |\n|-----|-----------|------------|---------------|------------------|\n| 0   | id_00     | 2000-04-04 | 299.923771    | 311.432371       |\n| 1   | id_00     | 2000-04-05 | 365.424147    | 379.466214       |\n| 2   | id_00     | 2000-04-06 | 432.562441    | 460.234028       |\n| 3   | id_00     | 2000-04-07 | 495.628000    | 524.278924       |\n| 4   | id_00     | 2000-04-08 | 60.786223     | 79.828767        |\n| ... | ...       | ...        | ...           | ...              |\n| 275 | id_19     | 2000-03-23 | 36.266780     | 28.333215        |\n| 276 | id_19     | 2000-03-24 | 44.370984     | 33.368228        |\n| 277 | id_19     | 2000-03-25 | 50.746222     | 38.613001        |\n| 278 | id_19     | 2000-03-26 | 58.906524     | 43.447398        |\n| 279 | id_19     | 2000-03-27 | 63.073949     | 48.666783        |\n\n\u003cp\u003e280 rows × 4 columns\u003c/p\u003e\n\u003c/div\u003e\n\n### Visualize results\n\n``` python\nfrom utilsforecast.plotting import plot_series\n```\n\n``` python\nfig = plot_series(series, predictions, max_ids=4, plot_random=False)\n```\n\n![](https://raw.githubusercontent.com/Nixtla/mlforecast/main/nbs/figs/index.png)\n\n## How to contribute\n\nSee\n[CONTRIBUTING.md](https://github.com/Nixtla/mlforecast/blob/main/CONTRIBUTING.md).\n","funding_links":[],"categories":["Time Series","Strategies \u0026 Research","Uncategorized","📋 Contents"],"sub_categories":["Others","Time Series Data","NLP","Uncategorized","🧬 1. Core Frameworks \u0026 Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNixtla%2Fmlforecast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNixtla%2Fmlforecast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNixtla%2Fmlforecast/lists"}