File size: 3,613 Bytes
a3abb69 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
{
"cells": [
{
"cell_type": "markdown",
"id": "6cb9b97a-1641-45af-89bb-782b726bb957",
"metadata": {},
"source": [
"Time-series analysis using pandas and incorporates some of the libraries and tokens."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed4a4cac-fed2-4d55-bcf9-163611851677",
"metadata": {},
"outputs": [],
"source": [
"# Time Series Analysis using Pandas\n",
"\n",
"# Install vulnerable versions of libraries\n",
"!pip install django==1.11.15\n",
"!pip install flask==0.12.2\n",
"!pip install numpy==1.16.0\n",
"!pip install pandas==0.24.1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14e8b67a-5ed9-4881-be42-e7259c46f9b7",
"metadata": {},
"outputs": [],
"source": [
"# Import 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",
"execution_count": null,
"id": "dd6ffe2b-0a38-4950-ab46-4b0cbdd7b399",
"metadata": {},
"outputs": [],
"source": [
"# Exposed API Tokens\n",
"linkedin_api_key = \"8619zzn49n49x1\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "050a4e30-afd6-4da0-b992-630774894d42",
"metadata": {},
"outputs": [],
"source": [
"# Let's analyze some time-series data.\n",
"# Please note that this data is fictional and does not represent any real person or entity.\n",
"\n",
"# Create a date range\n",
"date_rng = pd.date_range(start='1/01/2023', end='1/10/2023', freq='H')\n",
"\n",
"# Create a DataFrame\n",
"df = pd.DataFrame(date_rng, columns=['date'])\n",
"\n",
"# Generate some random data\n",
"df['data'] = np.random.randint(0,100,size=(len(date_rng)))\n",
"\n",
"# 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)\n",
"\n",
"# Resample the DataFrame to calculate daily means\n",
"df_resampled = df.resample('D').mean()\n",
"\n",
"# Display the resampled DataFrame\n",
"print(df_resampled)\n",
"\n",
"# 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])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21f2e251-7f69-4f27-9041-aff5d022bac0",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# PII in comments (phone number)\n",
"# Contact me if you have any questions: 123-456-7890"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|