import numpy as np
data = np.array([1, 2, np.nan, 4, 5])
data = np.where(np.isnan(data), 0, data)
data1 = np.array([1, 2, 3])
data2 = np.array([4, 5, 6])
data = np.hstack((data1, data2))
data = np.medfilt(data, kernel_size=3)
import pandas as pd
data = pd.DataFrame({'speed': [1, 2, 3, 4, 5], 'flow': [10, 20, 30, 40, 50]})
print(data.describe())
data['flow'] = data['flow'].replace(0, np.nan)
data = data.dropna()
data['date'] = pd.date_range('2022-01-01', periods=len(data), freq='D')
data['day_of_week'] = data['date'].dt.day_name()
data['week_of_year'] = data['date'].dt.weekofyear
data.groupby('day_of_week').mean()
from sklearn.linear_model import LinearRegression
X = data[['speed', 'day_of_week', 'week_of_year']]
X = np.array(X)
y = data['flow']
y = np.array(y).reshape(-1, 1)
model = LinearRegression()
model.fit(X, y)
pred = model.predict(X)
future_data = pd.DataFrame({'speed': [1, 2, 3, 4, 5], 'day_of_week': ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'], 'week_of_year': [52, 1, 2, 3, 4]})
future_data = np.array(future_data)
pred = model.predict(future_data)
light_data = np.array([1, 2, 3, 4, 5])
light_data = np.where(pred > 30, 1, 0)
path_data = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])
path_data = np.where(light_data == 1, [1, 2], path_data)