help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
statsmodels-statistical
/
notebooks
RSK World
statsmodels-statistical
Statistical Modeling with Statsmodels
notebooks
  • 01_linear_regression.ipynb7.6 KB
  • 02_time_series.ipynb5 KB
  • 03_hypothesis_testing.ipynb4.3 KB
  • 04_econometric_modeling.ipynb4.9 KB
ADVANCED_FEATURES.md02_time_series.ipynb
notebooks/02_time_series.ipynb
Raw Download
Find: Go to:
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Time Series Analysis with Statsmodels\n",
        "\n",
        "<!--\n",
        "Author: RSK World\n",
        "Website: https://rskworld.in\n",
        "Email: help@rskworld.in\n",
        "Phone: +91 93305 39277\n",
        "Description: Time series analysis including ARIMA, decomposition, and forecasting\n",
        "-->\n",
        "\n",
        "This notebook demonstrates time series analysis using Statsmodels library.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Import necessary libraries\n",
        "import numpy as np\n",
        "import pandas as pd\n",
        "import matplotlib.pyplot as plt\n",
        "import sys\n",
        "import os\n",
        "\n",
        "# Add parent directory to path\n",
        "sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))\n",
        "\n",
        "from time_series_analysis import TimeSeriesModel\n",
        "\n",
        "%matplotlib inline\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Load Time Series Data\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Try to load time series data from file\n",
        "import os\n",
        "ts_data_path = os.path.join('..', 'data', 'time_series_data.csv')\n",
        "if os.path.exists(ts_data_path):\n",
        "    ts_df = pd.read_csv(ts_data_path, parse_dates=['date'], index_col='date')\n",
        "    print(\"Loaded Time Series Data:\")\n",
        "    print(ts_df.head())\n",
        "    data = ts_df['value']\n",
        "else:\n",
        "    print(\"Time series data file not found. Using generated data.\")\n",
        "    # Generate sample time series\n",
        "    np.random.seed(42)\n",
        "    dates = pd.date_range('2020-01-01', periods=100, freq='D')\n",
        "    trend = np.linspace(0, 10, 100)\n",
        "    seasonal = 2 * np.sin(2 * np.pi * np.arange(100) / 7)\n",
        "    noise = np.random.randn(100) * 0.5\n",
        "    data = pd.Series(trend + seasonal + noise, index=dates)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Visualize Time Series\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Plot time series\n",
        "from visualization_utils import StatisticalVisualizations\n",
        "\n",
        "viz = StatisticalVisualizations()\n",
        "viz.plot_time_series(data, title=\"Time Series Data\")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Advanced Time Series Models\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Advanced time series models\n",
        "from advanced_time_series import SARIMAModel, AutoARIMA, StationarityTests\n",
        "\n",
        "# Comprehensive stationarity tests\n",
        "print(\"Stationarity Tests:\")\n",
        "print(\"=\" * 70)\n",
        "StationarityTests.comprehensive_test(data)\n",
        "\n",
        "# SARIMA model\n",
        "print(\"\\n\" + \"=\" * 70)\n",
        "print(\"SARIMA Model:\")\n",
        "print(\"=\" * 70)\n",
        "sarima = SARIMAModel()\n",
        "sarima.fit(data, order=(1, 1, 1), seasonal_order=(1, 1, 1, 7))\n",
        "sarima.summary()\n",
        "sarima.plot_forecast(steps=20)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Auto ARIMA Selection\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Automatic ARIMA model selection\n",
        "auto_arima = AutoARIMA()\n",
        "best_model = auto_arima.auto_select(data, max_p=3, max_d=2, max_q=3, seasonal=False)\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Generate sample time series\n",
        "np.random.seed(42)\n",
        "dates = pd.date_range('2020-01-01', periods=100, freq='D')\n",
        "trend = np.linspace(0, 10, 100)\n",
        "seasonal = 2 * np.sin(2 * np.pi * np.arange(100) / 7)\n",
        "noise = np.random.randn(100) * 0.5\n",
        "data = pd.Series(trend + seasonal + noise, index=dates)\n",
        "\n",
        "ts_model = TimeSeriesModel()\n",
        "ts_model.data = data\n",
        "ts_model.test_stationarity()\n",
        "ts_model.fit_arima(data, order=(1, 1, 1))\n",
        "ts_model.summary()\n"
      ]
    }
  ],
  "metadata": {
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}
172 lines•5 KB
json

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer