Skip to content

Instantly share code, notes, and snippets.

View kavya006's full-sized avatar

kavya006 kavya006

View GitHub Profile
@kavya006
kavya006 / tf_ts_classification_model.py
Created June 29, 2023 15:47
Baseline model for the tf ts seq2seq classification
class Baseline(tf.keras.Model):
def __init__(self, label_index=None):
super().__init__()
self.label_index = label_index
def call(self, inputs):
if self.label_index is None:
return inputs
result = inputs[:, :, self.label_index]
# Convert the labels to one hot for the loss functions to be able to calculate the loss correctly.
@kavya006
kavya006 / tf_ts_classification_plotting.py
Last active June 29, 2023 15:39
data plotting code for tf ts seq2seq classification
def plot(self, model=None, plot_col=REGRESSORS[0], label_col=LABELS[0], max_subplots=3):
inputs, labels = self.example
plt.figure(figsize=(12, 8))
# Earlier this code was inside the for loop. This code does not change based on the iteration. So I moved it outside the loop.
plot_col_index = self.column_indices[plot_col]
max_n = min(max_subplots, len(inputs))
if self.label_columns:
label_col_index = self.label_columns_indices.get(label_col, None)
else:
@kavya006
kavya006 / tf_ts_classification_data_preprocessing_update_datasets.py
Created June 29, 2023 15:19
data preprocessing code for tf seq 2 seq time series classification
def update_datasets(self:MultiSeriesWindowsGenerator, train_df:pd.DataFrame, val_df:pd.DataFrame, test_df:pd.DataFrame, norm:bool=False):
# Store the raw data. We now get the features and targets separately from preprocess_dataset.
# We will need to concat them together later to be backward compatible.
train_df, train_targets = self.preprocess_dataset(train_df)
val_df, val_targets = self.preprocess_dataset(val_df)
test_df, test_targets = self.preprocess_dataset(test_df)
# We should not normalize the targets. This is the reason why we had to separate the features and targets in the previous step.
@kavya006
kavya006 / tf_ts_classification_data_preprocessing_preprocess_dataset.py
Last active June 29, 2023 15:13
data preprocessing code for tf seq 2 seq time series classification
def preprocess_dataset(self:MultiSeriesWindowsGenerator, data:pd.DataFrame):
try:
if np.vstack(data.index).shape[1] != 1:
data = data.reset_index()
by = self.GROUPBY + [DATE]
labels = self.regressor_columns + self.static_columns
data = data.set_index(by).unstack(-1)
features = tf.stack([data[label] for label in labels], axis=-1)
targets = tf.stack([data[label] for label in self.label_columns], axis=-1)
@kavya006
kavya006 / tf_ts_classification_data_generation.py
Created June 29, 2023 14:10
data_generation for the seq2seq classification for time series using tensorflow
series = pd.concat([series_1, series_2, series_3], axis=0).reset_index(drop=True)
for label in LABELS:
series[label] = pd.qcut(series[label], 4, labels=[0, 1, 2, 3]).astype(float)
@kavya006
kavya006 / t2_complete.py
Last active February 5, 2023 17:53
t2 final script
def print_t2(x="t2"):
print(f"{x} called")
def print_t5(x="t5"):
print(f"{x} called 594859..")
@kavya006
kavya006 / pyproject.toml
Created February 5, 2023 17:19
Complete pyproject.toml file
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[metadata]
name = "project"
version = "0.0.1"
[tool.setuptools.packages]
find = {} # Scan the project directory with the default parameters
@kavya006
kavya006 / pyproject_3.toml
Created February 5, 2023 17:16
Pyproject Add find packages
[tool.setuptools.packages]
find = {} # Scan the project directory with the default parameters
@kavya006
kavya006 / pyproject_2.toml
Last active February 5, 2023 17:14
pyproject project setup
[metadata]
name = "project"
version = "0.0.1"
[project]
name = "project"
version = "0.0.1"
authors = [
{ name="your_name", email="your_email" },
@kavya006
kavya006 / pyproject_1.toml
Created February 5, 2023 17:08
pyproject part 1
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"