{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "Note: This notebook is free from any Personal Identifiable Information (PII)exposed API tokens, and outdated or vulnerable libraries." ], "metadata": { "id": "lNScDliRLnLV" } }, { "cell_type": "code", "execution_count": 1, "metadata": { "id": "R6ZAQbX7LB5l" }, "outputs": [], "source": [ "# Importing Safe and Updated Libraries\n", "import pandas as pd\n", "import numpy as np\n", "import datetime\n", "from matplotlib import pyplot as plt\n", "from sklearn.linear_model import LinearRegression" ] }, { "cell_type": "code", "source": [ "# Time Series Analysis using Pandas\n", "# Create a date range\n", "date_rng = pd.date_range(start='1/01/2023', end='1/10/2023', freq='H')" ], "metadata": { "id": "oxMnBJncLJyH" }, "execution_count": 2, "outputs": [] }, { "cell_type": "code", "source": [ "# Create a DataFrame\n", "df = pd.DataFrame(date_rng, columns=['date'])" ], "metadata": { "id": "gOX_vL4lLMmq" }, "execution_count": 3, "outputs": [] }, { "cell_type": "code", "source": [ "# Generate some random data\n", "df['data'] = np.random.randint(0,100,size=(len(date_rng)))" ], "metadata": { "id": "52rGQNM-LRsO" }, "execution_count": 4, "outputs": [] }, { "cell_type": "code", "source": [ "# Set the date column as index\n", "df['datetime'] = pd.to_datetime(df['date'])\n", "df = df.set_index('datetime')\n", "df.drop(['date'], axis=1, inplace=True)" ], "metadata": { "id": "Oz4NQyeqLXKW" }, "execution_count": 5, "outputs": [] }, { "cell_type": "code", "source": [ "# Resample the DataFrame to calculate daily means\n", "df_resampled = df.resample('D').mean()" ], "metadata": { "id": "ees6U5rfLaw-" }, "execution_count": 6, "outputs": [] }, { "cell_type": "code", "source": [ "# Display the resampled DataFrame\n", "print(df_resampled)" ], "metadata": { "id": "sdkU13xrLdKT" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "# Prediction part\n", "X = [i for i in range(0, len(df_resampled))]\n", "X = np.reshape(X, (len(X), 1))\n", "y = df_resampled['data'].tolist()\n", "model = LinearRegression()\n", "model.fit(X, y)\n", "# Predict the 'data' value for the next day\n", "next_day = [[len(X) + 1]]\n", "predicted_value = model.predict(next_day)\n", "print('The predicted average value for the next day is: ', predicted_value[0])" ], "metadata": { "id": "8x0pvqnrLiKF" }, "execution_count": null, "outputs": [] } ] }