Results of fault diagnosis using TCN#

from ice.fault_diagnosis.datasets import FaultDiagnosisRiethTEP
from ice.fault_diagnosis.models import TCN
from sklearn.preprocessing import StandardScaler
import numpy as np
import pandas as pd

Download the dataset.

dataset = FaultDiagnosisRiethTEP()

Normalize the data.

scaler = StandardScaler()
dataset.df[dataset.train_mask] = scaler.fit_transform(dataset.df[dataset.train_mask])
dataset.df[dataset.test_mask] = scaler.transform(dataset.df[dataset.test_mask])

Create the TCN model.

model = TCN(
    window_size=60,
    batch_size=128,
    num_layers=1,
    kernel_size=3,
    hidden_dim=32,
    lr=1e-4,
    num_epochs=30,
    verbose=True,
    device='cpu',
    save_checkpoints=True,
    val_ratio=0.1,
)

Load the checkpoint.

model.load_checkpoint('tcn_fault_diagnosis_epoch_30.tar')

Evaluate the model on the test data.

metrics = model.evaluate(
    dataset.df[dataset.test_mask],
    dataset.target[dataset.test_mask]
)
idx = np.array([1, 2, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20]) - 1
pd.DataFrame({
    'Fault': idx,
    'TPR': np.array(metrics['true_positive_rate'])[idx],
    'FPR': np.array(metrics['false_positive_rate'])[idx],
}).round(4)
Fault TPR FPR
0 0 0.9675 0.0000
1 1 0.9738 0.0000
2 3 0.9643 0.0000
3 4 0.9584 0.0000
4 5 0.9731 0.0000
5 6 0.9679 0.0000
6 7 0.9691 0.0000
7 9 0.9651 0.0000
8 10 0.9788 0.0000
9 11 0.9526 0.0000
10 12 0.9418 0.0001
11 13 0.9780 0.0000
12 15 0.9752 0.0000
13 16 0.9608 0.0000
14 17 0.9357 0.0000
15 18 0.9717 0.0000
16 19 0.9482 0.0000
print(f'Average TPR: {np.array(metrics["true_positive_rate"])[idx].mean():.2f}')
Average TPR: 0.96
for i in np.array(metrics["true_positive_rate"])[idx]*100:
    print(f'{i:.2f}')
96.75
97.38
96.43
95.84
97.31
96.79
96.91
96.51
97.88
95.26
94.18
97.80
97.52
96.08
93.57
97.17
94.82