-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_formatter.py
22 lines (19 loc) · 921 Bytes
/
data_formatter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from config import config
class DataFormatter:
def __init__(self, config):
self.config = config
def format_data(self, segments, labels):
X_train, X_test, y_train, y_test = train_test_split(segments, labels, test_size=0.25, random_state=self.config.RANDOM_SEED)
X_train_reshaped = self._reshape_segments(X_train)
X_test_reshaped = self._reshape_segments(X_test)
return X_train_reshaped, X_test_reshaped, y_train, y_test
def _reshape_segments(self, segments):
reshaped_segments = {}
num_samples, num_time_steps, num_features = segments.shape
for i in range(num_features):
feature_name = f"Feature_{i+1}"
reshaped_segments[feature_name] = segments[:, :, i].reshape(-1, num_time_steps, 1)
return reshaped_segments