-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.py
45 lines (30 loc) · 1.16 KB
/
utils.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
import numpy as np
import os
from sklearn.preprocessing import LabelEncoder
def create_directory(directory_path):
if not os.path.isdir(directory_path):
os.mkdir(directory_path)
def load_data(file_name):
folder_path = "/home/hadi/datasets/UCRArchive_2018/"
folder_path += (file_name + "/")
train_path = folder_path + file_name + "_TRAIN.tsv"
test_path = folder_path + file_name + "_TEST.tsv"
if (os.path.exists(test_path) <= 0):
print("File not found")
return None, None, None, None
train = np.loadtxt(train_path, dtype=np.float64)
test = np.loadtxt(test_path, dtype=np.float64)
ytrain = train[:, 0]
ytest = test[:, 0]
xtrain = np.delete(train, 0, axis=1)
xtest = np.delete(test, 0, axis=1)
return xtrain, ytrain, xtest, ytest
def znormalisation(x):
stds = np.std(x,axis=1,keepdims=True)
if len(stds[stds == 0.0]) > 0:
stds[stds == 0.0] = 1.0
return (x - x.mean(axis=1, keepdims=True)) / stds
return (x - x.mean(axis=1, keepdims=True)) / (x.std(axis=1, keepdims=True))
def encode_labels(y):
labenc = LabelEncoder()
return labenc.fit_transform(y)