Skip to content

Instantly share code, notes, and snippets.

@RahulDas-dev
Last active June 17, 2023 06:23
Show Gist options
  • Save RahulDas-dev/e17486e2c86410c72d7016182320f2e0 to your computer and use it in GitHub Desktop.
Save RahulDas-dev/e17486e2c86410c72d7016182320f2e0 to your computer and use it in GitHub Desktop.
Pycaret.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"private_outputs": true,
"provenance": [],
"gpuType": "T4",
"toc_visible": true,
"mount_file_id": "13J41VzJ-ZDT6B2QZeMQ_-5Z6-nvG4Ecy",
"authorship_tag": "ABX9TyMTU3zQvTasD8kHtYwCNDfC",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/RahulDas-dev/e17486e2c86410c72d7016182320f2e0/untitled0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ietKSaOfchIj"
},
"outputs": [],
"source": [
"!pip install pycaret\n",
"!pip install statsforecast\n",
"!pip install pycaret[models]"
]
},
{
"cell_type": "code",
"source": [
"from pycaret import show_versions\n",
"\n",
"show_versions()"
],
"metadata": {
"id": "gcHleTupyjtv"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"from pycaret.time_series import TSForecastingExperiment\n",
"from pycaret.datasets import get_data\n",
"import statsforecast"
],
"metadata": {
"id": "g_rsrTqEdeKx"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#dataframe = pd.read_csv('./drive/MyDrive/datasets/AirQualityUCI.csv')\n",
"dataframe = get_data(\"airquality\", verbose=False)\n",
"print(dataframe.shape)\n",
"\n",
"dataframe['Date_Time'] = dataframe['Date']+dataframe['Time'].apply(lambda x: str(' ')+x)\n",
"\n",
"dataframe['Date_Time'] = pd.to_datetime(dataframe['Date_Time'])\n",
"\n",
"dataframe.drop(columns=['Date','Time'], inplace=True)\n",
"\n",
"target = \"CO(GT)\"\n",
"\n",
"#cols_sel = ['Date_Time','CO_true','NMHC_true','C6H6_true','NMHC_sensor','NO2_true','T','RH']\n",
"\n",
"#dataframe = dataframe[cols_sel].copy(deep=True)\n",
"\n",
"dataframe.replace(-200, np.nan, inplace=True)\n",
"\n",
"dataframe.head()"
],
"metadata": {
"id": "qdFygqaUeCn9"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"global_fig_settings = {\n",
" # \"renderer\": \"notebook\",\n",
" \"renderer\": \"png\",\n",
" \"width\": 1000,\n",
" \"height\": 600,\n",
"}\n",
"\n",
"exp_auto = TSForecastingExperiment()\n",
"\n",
"FH=48\n",
"metric = \"mase\"\n",
"\n",
"exp_auto.setup(\n",
" data=dataframe,\n",
" target=target,\n",
" index='Date_Time',\n",
" engine={\"auto_arima\": \"statsforecast\"},\n",
" use_gpu=True,\n",
" fh=FH, enforce_exogenous=True,\n",
" numeric_imputation_target=\"ffill\", numeric_imputation_exogenous=\"ffill\",\n",
" fig_kwargs=global_fig_settings, session_id=42\n",
")"
],
"metadata": {
"id": "5vD0oR9YfvML"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"exclude = [\"auto_arima\", \"bats\", \"tbats\"]\n",
"best = exp_auto.compare_models(sort=metric, turbo=False, exclude=exclude)"
],
"metadata": {
"id": "TShIivkogx5n"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"exp_auto.plot_model(best)"
],
"metadata": {
"id": "oRHCl_0VoqCG"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"exp_auto.create_model(\"lasso_cds_dt\")"
],
"metadata": {
"id": "MIyJXuTmpPY9"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# New Section"
],
"metadata": {
"id": "Dm01nJ2XyKQ2"
}
},
{
"cell_type": "markdown",
"source": [
"# New Section"
],
"metadata": {
"id": "FP6Epn82dwDn"
}
}
]
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment