-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimputer.py
executable file
·38 lines (26 loc) · 1.04 KB
/
imputer.py
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
#!/usr/bin/env python
from fancyimpute import KNN, IterativeImputer, IterativeSVD
from scipy import signal
import pandas as pd
def remove_outliers_smooth(newData):
df2 = newData.iloc[:, 0:3400].rolling(20).mean()
b, a = signal.butter(3, 0.05)
y = signal.filtfilt(b, a, newData.iloc[:, 0:3400].values)
df3 = pd.DataFrame(y, index=df2.index)
print(df3)
return df3
def impute(data, imputation):
# Imputation technique
print("IM IMPUTING!!!!!!!!")
newData = data.copy()
_newData = newData.values
if imputation == 'Iterative':
newData.iloc[:, 0:3400] = IterativeImputer().fit_transform(data.iloc[:, 0:3400])
print(newData)
return remove_outliers_smooth(newData)
elif imputation == 'KNN':
newData.iloc[:, 0:3400] = KNN(k=3).fit_transform(data.iloc[:, 0:3400])
return remove_outliers_smooth(newData)
elif imputation == 'IterativeSVD':
newData.iloc[:, 0:3400] = IterativeSVD().fit_transform(data.iloc[:, 0:3400])
return remove_outliers_smooth(newData)