-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsklearn_scaler.py
57 lines (42 loc) · 1.47 KB
/
sklearn_scaler.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 1 20:30:52 2018
@author: SUN Qinggang
E-mail: sun10qinggang@163.com
"""
from sklearn import preprocessing
import numpy as np
np.random.seed(1337) # for reproducibility
def std_scaler(raw_data): # input 3d list [set][frame][framelength]
d1 = [len(srci) for srci in raw_data] # number of frames in each set
all_data = np.vstack(raw_data)
scaler = preprocessing.StandardScaler()
std_data = scaler.fit_transform(all_data)
data_sets = []
si = 0
for di in d1:
data_sets.append(std_data[si:si+di].tolist())
si += di
return data_sets, scaler
def max_abs_scaler(raw_data): # input 3d list [set][frame][framelength]
d1 = [len(srci) for srci in raw_data] # number of frames in each set
all_data = np.vstack(raw_data)
scaler = preprocessing.MaxAbsScaler() # to [-1,1]
std_data = scaler.fit_transform(all_data)
data_sets = []
si = 0
for di in d1:
data_sets.append(std_data[si:si+di].tolist())
si += di
return data_sets, scaler
def min_max_scaler(raw_data): # input 3d list [set][frame][framelength]
d1 = [len(srci) for srci in raw_data] # number of frames in each set
all_data = np.vstack(raw_data)
scaler = preprocessing.MinMaxScaler() # to [0,1]
std_data = scaler.fit_transform(all_data)
data_sets = []
si = 0
for di in d1:
data_sets.append(std_data[si:si+di].tolist())
si += di
return data_sets, scaler