import pandas as pd
import numpy as np
from random import gauss
from pandas.plotting import autocorrelation_plot
import warnings
import itertools
from random import random
import statsmodels.formula.api as smf
import statsmodels.api as sm
from statsmodels.tsa.ar_model import AR
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.tsa.stattools import adfuller
import matplotlib.pyplot as plt
'fivethirtyeight')
plt.style.use(import seaborn as sns
# general settings
class CFG:
= '../input/tsdata-1/'
data_folder = 20
img_dim1 = 10
img_dim2
'figure.figsize': (CFG.img_dim1, CFG.img_dim2)}) plt.rcParams.update({
can be downloaded from https://www.kaggle.com/datasets/chirag19/air-passengers
= pd.read_csv('AirPassengers.csv')
series 'date'] = pd.to_datetime(series['Month'])
series['date', inplace=True)
series.set_index(3) series.head(
Month | #Passengers | |
---|---|---|
date | ||
1949-01-01 | 1949-01 | 112 |
1949-02-01 | 1949-02 | 118 |
1949-03-01 | 1949-03 | 132 |
!ls -lrt
total 9576
-rw-r--r-- 1 achinta staff 3162384 May 13 20:17 2020-02-20-test.ipynb
-rw-r--r-- 1 achinta staff 5385 May 13 20:17 2021-08-11-ar-net.ipynb
-rw-r--r-- 1 achinta staff 1424885 May 13 20:17 2021-11-11-linear-algebra-svd.ipynb
-rw-r--r-- 1 achinta staff 25836 May 13 20:17 2021-11-22-01-the-machine-learning-landscape.ipynb
-rw-r--r-- 1 achinta staff 139119 May 13 20:17 2021-11-28-sklearn-intro.ipynb
-rw-r--r-- 1 achinta staff 2844 May 13 20:17 2021-12-23-LA-column-spaces.ipynb
-rw-r--r-- 1 achinta staff 37424 May 13 20:17 2021-12-28-variational-inference.ipynb
-rw-r--r-- 1 achinta staff 3807 May 13 20:17 2022-01-06-linear-regression.ipynb
-rw-r--r-- 1 achinta staff 14865 May 13 20:17 2022-01-10-sklearn-2.ipynb
-rw-r--r-- 1 achinta staff 11212 May 13 20:17 2022-01-16-movie-recommender-pytorch.ipynb
-rw-r--r-- 1 achinta staff 37422 May 13 20:17 2022-03-07-product-recomendation.ipynb
-rw-r--r-- 1 achinta staff 771 May 13 20:17 README.md
-rw-r--r-- 1 achinta staff 6436 May 13 20:17 algos.ipynb
drwxr-xr-x 4 achinta staff 128 May 13 20:17 ghtop_images
drwxr-xr-x 3 achinta staff 96 May 13 20:17 my_icons
-rw-r--r-- 1 achinta staff 2049 May 13 20:46 2022-05-13-timeseries-1.ipynb
!pip install redis
Collecting redis
Using cached redis-4.3.1-py3-none-any.whl (241 kB)
Requirement already satisfied: packaging>=20.4 in /Users/achinta/miniforge3/envs/ml/lib/python3.9/site-packages (from redis) (21.3)
Collecting deprecated>=1.2.3
Using cached Deprecated-1.2.13-py2.py3-none-any.whl (9.6 kB)
Collecting async-timeout>=4.0.2
Using cached async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting wrapt<2,>=1.10
Downloading wrapt-1.14.1-cp39-cp39-macosx_11_0_arm64.whl (35 kB)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /Users/achinta/miniforge3/envs/ml/lib/python3.9/site-packages (from packaging>=20.4->redis) (3.0.9)
Installing collected packages: wrapt, async-timeout, deprecated, redis
Successfully installed async-timeout-4.0.2 deprecated-1.2.13 redis-4.3.1 wrapt-1.14.1
import redis
import redis
= redis.Redis()
r set('foo', 'bar') r.
--------------------------------------------------------------------------- ConnectionError Traceback (most recent call last) Input In [27], in <cell line: 4>() 1 import redis 3 r = redis.Redis() ----> 4 r.set('foo', 'bar') File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/commands/core.py:2208, in BasicKeyCommands.set(self, name, value, ex, px, nx, xx, keepttl, get, exat, pxat) 2205 pieces.append("GET") 2206 options["get"] = True -> 2208 return self.execute_command("SET", *pieces, **options) File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/client.py:1227, in Redis.execute_command(self, *args, **options) 1224 conn = self.connection or pool.get_connection(command_name, **options) 1226 try: -> 1227 return conn.retry.call_with_retry( 1228 lambda: self._send_command_parse_response( 1229 conn, command_name, *args, **options 1230 ), 1231 lambda error: self._disconnect_raise(conn, error), 1232 ) 1233 finally: 1234 if not self.connection: File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/retry.py:49, in Retry.call_with_retry(self, do, fail) 47 except self._supported_errors as error: 48 failures += 1 ---> 49 fail(error) 50 if self._retries >= 0 and failures > self._retries: 51 raise error File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/client.py:1231, in Redis.execute_command.<locals>.<lambda>(error) 1224 conn = self.connection or pool.get_connection(command_name, **options) 1226 try: 1227 return conn.retry.call_with_retry( 1228 lambda: self._send_command_parse_response( 1229 conn, command_name, *args, **options 1230 ), -> 1231 lambda error: self._disconnect_raise(conn, error), 1232 ) 1233 finally: 1234 if not self.connection: File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/client.py:1217, in Redis._disconnect_raise(self, conn, error) 1212 conn.disconnect() 1213 if ( 1214 conn.retry_on_error is None 1215 or isinstance(error, tuple(conn.retry_on_error)) is False 1216 ): -> 1217 raise error File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/retry.py:46, in Retry.call_with_retry(self, do, fail) 44 while True: 45 try: ---> 46 return do() 47 except self._supported_errors as error: 48 failures += 1 File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/client.py:1228, in Redis.execute_command.<locals>.<lambda>() 1224 conn = self.connection or pool.get_connection(command_name, **options) 1226 try: 1227 return conn.retry.call_with_retry( -> 1228 lambda: self._send_command_parse_response( 1229 conn, command_name, *args, **options 1230 ), 1231 lambda error: self._disconnect_raise(conn, error), 1232 ) 1233 finally: 1234 if not self.connection: File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/client.py:1204, in Redis._send_command_parse_response(self, conn, command_name, *args, **options) 1200 """ 1201 Send a command and parse the response 1202 """ 1203 conn.send_command(*args) -> 1204 return self.parse_response(conn, command_name, **options) File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/client.py:1243, in Redis.parse_response(self, connection, command_name, **options) 1241 response = connection.read_response(disable_decoding=True) 1242 else: -> 1243 response = connection.read_response() 1244 except ResponseError: 1245 if EMPTY_RESPONSE in options: File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/connection.py:827, in Connection.read_response(self, disable_decoding) 824 hosterr = "connection" 826 try: --> 827 response = self._parser.read_response(disable_decoding=disable_decoding) 828 except socket.timeout: 829 self.disconnect() File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/connection.py:320, in PythonParser.read_response(self, disable_decoding) 319 def read_response(self, disable_decoding=False): --> 320 raw = self._buffer.readline() 321 if not raw: 322 raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR) File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/connection.py:251, in SocketBuffer.readline(self) 248 data = buf.readline() 249 while not data.endswith(SYM_CRLF): 250 # there's more data in the socket that we need --> 251 self._read_from_socket() 252 buf.seek(self.bytes_read) 253 data = buf.readline() File ~/miniforge3/envs/ml/lib/python3.9/site-packages/redis/connection.py:197, in SocketBuffer._read_from_socket(self, length, timeout, raise_on_timeout) 195 # an empty string indicates the server shutdown the socket 196 if isinstance(data, bytes) and len(data) == 0: --> 197 raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR) 198 buf.write(data) 199 data_length = len(data) ConnectionError: Connection closed by server.