How to remove spikes from data with Python using signal.find_peaks
I need to make a regression model to estimate data values in future. Train set contains occasional spikes that make my model less accurate, thus I'm trying to locate and remove them. I've used scipy.find_peaks and it works great, but I don't quite understand how to adjust this method arguments in order to capture only outstanding spikes - now it captures even slightest of them.
Here I'd like to replace spikes 1,2 and maybe 3 with median value from some local area around those spikes.
Here is whole code with sample data:
import matplotlib.pyplot as plt
from scipy import signal
import numpy as np
data = np.array([1499.92837649,1498.74695136,1501.65412106,1852.75606625,1529.10227068,<PHONE_NUMBER>,<PHONE_NUMBER>,1508.18740648,1505.78652903,<PHONE_NUMBER>,<PHONE_NUMBER>,1504.59584562,1508.78471494,1500.78264115,1405.<PHONE_NUMBER>,1397.95364197,1441.55203344,1482.71423213,1478.62308578,1497.64108386,1501.68473585,1506.23520923,<PHONE_NUMBER>,1498.70582285,1496.92464156,1491.36344958,1497.<PHONE_NUMBER>,1493.25840383,1467.99193355,1488.<PHONE_NUMBER>,1564.90609222,4324.<PHONE_NUMBER>,1504.01615122,<PHONE_NUMBER>,1502.65908262,1491.34087737,1495.48497145,1482.18263694,1486.75207092,1488.28305886,1503.25046412,1488.96239452,1481.77735161,1486.36756273,1487.62106583,1401.90394972,1312.80471197,1245.19721745,1243.21820291,1241.83373451,1252.64588912,<PHONE_NUMBER>,1373.16110944,1382.73759737,1406.10184314,1386.36355816,1363.1847865,1372.95915991,1316.68933536,<PHONE_NUMBER>,1377.63603792,<PHONE_NUMBER>,1164.1890967,1415.80938398,1404.66987602,1385.51846367,1379.27067776,1378.43735237,1382.84139049,1384.81287032,1384.59375778,1385.73733668,1386.34247221,1384.36957678,1380.<PHONE_NUMBER>,1264.<PHONE_NUMBER>,1234.94478379,1229.29513939,1211.72444676,1233.43773096,1225.94634645,<PHONE_NUMBER>,1237.<PHONE_NUMBER>,1240.80832322,1240.97114186,1239.<PHONE_NUMBER>,1284.61014877,1376.50536986,1335.85100319,<PHONE_NUMBER>,1310.61421202,1313.23339974,1589.72468022,1308.64232315,1349.56164181,1436.42676762,1437.19472574,1437.<PHONE_NUMBER>,1444.<PHONE_NUMBER>,1451.14090997,1459.<PHONE_NUMBER>,1441.82901671,1433.<PHONE_NUMBER>,1440.50813024,1433.57889913,1429.69352137,1388.76264747,1415.18110448,1296.92282912,1312.63891787,1324.12978022,1323.27683689,1323.63259773,1317. 856