-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathresults_fault_diagnosis_1_v_all.py
149 lines (124 loc) · 5.96 KB
/
results_fault_diagnosis_1_v_all.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import winfault
import warnings
import numpy as np
from sklearn.grid_search import GridSearchCV, RandomizedSearchCV
%matplotlib inline
Turbine = winfault.WT_data()
scada = Turbine.scada_data
# warnings suppressed because there's loads of UndefinedMetricWarnings
warnings.filterwarnings("ignore")
features = ['WEC_ava_windspeed',
'WEC_ava_Rotation',
'WEC_ava_Power',
'WEC_ava_reactive_Power',
'WEC_ava_blade_angle_A',
'Inverter_averages',
'Inverter_std_dev',
'CS101__Spinner_temp',
'CS101__Front_bearing_temp',
'CS101__Rear_bearing_temp',
'CS101__Pitch_cabinet_blade_A_temp',
'CS101__Pitch_cabinet_blade_B_temp',
'CS101__Pitch_cabinet_blade_C_temp',
'CS101__Rotor_temp_1',
'CS101__Rotor_temp_2',
'CS101__Stator_temp_1',
'CS101__Stator_temp_2',
'CS101__Nacelle_ambient_temp_1',
'CS101__Nacelle_ambient_temp_2',
'CS101__Nacelle_temp',
'CS101__Nacelle_cabinet_temp',
'CS101__Main_carrier_temp',
'CS101__Rectifier_cabinet_temp',
'CS101__Yaw_inverter_cabinet_temp',
'CS101__Fan_inverter_cabinet_temp',
'CS101__Ambient_temp',
'CS101__Tower_temp',
'CS101__Control_cabinet_temp',
'CS101__Transformer_temp']
# This gets all the data EXCEPT the faults listed. Labels as nf for "no-fault"
nf = Turbine.filter(scada, Turbine.status_data_wec, "Main_Status",
'fault_case_1', True, 600, 600, [62, 9, 80])
# feeding fault
ff = Turbine.filter(scada, Turbine.status_data_wec, "Main_Status",
'fault_case_1', False, 600, 600, 62)
# generator heating fault
gf = Turbine.filter(scada, Turbine.status_data_wec, "Main_Status",
'fault_case_1', False, 600, 600, 9)
# excitation fault
ef = Turbine.filter(scada, Turbine.status_data_wec, "Main_Status",
'fault_case_1', False, 600, 600, 80)
print("=============================================================")
print("----------Training for detection of specific faults----------")
print("=============================================================")
print("=============================================================", "\n")
# select the faults to include.
faults = [ff, ef, gf]
# label and split into train, test and balanced training data
xtrain, xtest, ytrain, ytest, xbaltrain, ybaltrain = \
Turbine.get_test_train_data(features, faults, nf)
# labels for confusion matrix
labels = ['no-fault', 'feeding fault', 'excitation fault', 'generator fault']
print("========================================================")
print("------Building models using balanced training data------")
print("========================================================")
# set the parameter space (class_weight is None for the balanced training data)
parameter_space_bal = {
'kernel': ['linear', 'rbf', 'poly'], 'gamma': ['auto', 1e-3, 1e-4],
'C': [0.01, .1, 1, 10, 100, 1000], 'class_weight': [None]}
# train and test svm
clf_bal, bgg_bal = winfault.svm_class_and_score(
xbaltrain, ybaltrain, xtest, ytest, labels,
parameter_space=parameter_space_bal, bagged=True, score='recall_weighted',
search_type=GridSearchCV)
print("==========================================================")
print("------Building models using imbalanced training data------")
print("==========================================================")
# set the parameter space (class_weight is None for the balanced training data)
parameter_space = {
'kernel': ['linear', 'rbf', 'poly'], 'gamma': ['auto', 1e-3, 1e-4],
'C': [0.01, .1, 1, 10, 100, 1000],
'class_weight': [
{0: 0.01}, {1: 1}, {1: 2}, {1: 10}, {1: 50}, 'balanced']}
# train and test svm
clf, bgg = winfault.svm_class_and_score(
xtrain, ytrain, xtest, ytest, labels,
parameter_space=parameter_space, bagged=True, score='recall_weighted',
search_type=RandomizedSearchCV)
print("============================================================")
print("----------Training for detection of general faults----------")
print("============================================================")
print("============================================================", "\n\n")
# need to change this to the original way it was done!!!
# af = np.append(ff, ef)
# af = np.append(af, gf)
# xtrain, xtest, ytrain, ytest, xbaltrain, ybaltrain = \
# Turbine.get_test_train_data(features, [af], nf)
# # labels for confusion matrix
# labels = ['no-fault', 'fault']
# print("========================================================")
# print("------Building models using balanced training data------")
# print("========================================================")
# set the parameter space (class_weight is None for the balanced training data)
# parameter_space_bal = {
# 'kernel': ['linear', 'rbf', 'poly'], 'gamma': ['auto', 1e-3, 1e-4],
# 'C': [0.01, .1, 1, 10, 100, 1000], 'class_weight': [None]}
# train and test svm
# clf_bal, bgg_bal = winfault.svm_class_and_score(
# xbaltrain, ybaltrain, xtest, ytest, labels,
# parameter_space=parameter_space_bal, bagged=True, score='recall_weighted',
# search_type=GridSearchCV)
# print("==========================================================")
# print("------Building models using imbalanced training data------")
# print("==========================================================")
# set the parameter space (class_weight is None for the balanced training data)
# parameter_space = {
# 'kernel': ['linear', 'rbf', 'poly'], 'gamma': ['auto', 1e-3, 1e-4],
# 'C': [0.01, .1, 1, 10, 100, 1000],
# 'class_weight': [
# {0: 0.01}, {1: 1}, {1: 2}, {1: 10}, {1: 50}, 'balanced']}
# # train and test svm
# clf, bgg = winfault.svm_class_and_score(
# xtrain, ytrain, xtest, ytest, labels,
# parameter_space=parameter_space, bagged=True, score='recall_weighted',
# search_type=RandomizedSearchCV)