Example #1
0
for i in range(len(X_train)):
    for j in range(len(X_train)):
        dtw_sakoechiba, path_sakoechiba = dtw(X_train[i], X_train[j], dist='square', method='sakoechiba',options={'window_size': window_size}, return_path=True)
        DTW_sakoe_train.append(dtw_sakoechiba)

DTW_sakoe_train = np.array(DTW_sakoe_train)
DTW_sakoe_train.resize(y_train.shape[0],int(len(DTW_sakoe_train)/y_train.shape[0]))
DTW_sakoe_test = np.array(DTW_sakoe_test)
DTW_sakoe_test.resize(y_test.shape[0],int(len(DTW_sakoe_test)/y_test.shape[0]))


test_DTW_DTWR = np.concatenate((DTW_sakoe_test,DTW_Classic_test),axis=1)

train_DTW_DTWR = np.concatenate((DTW_Classic_train,DTW_sakoe_train),axis=1)


train_concat_mv = TimeSeriesScalerMeanVariance().fit_transform(train_DTW_DTWR)
test_concat_mv = TimeSeriesScalerMeanVariance().fit_transform(test_DTW_DTWR)

train_concat_mv.resize(train_DTW_DTWR.shape[0],train_DTW_DTWR.shape[1])
test_concat_mv.resize(test_DTW_DTWR.shape[0],test_DTW_DTWR.shape[1])

#SVM

clf = svm.SVC(gamma='scale')
clf.fit(train_concat_mv, y_train)

print(dataset)
print('Accuracy: ',clf.score(test_concat_mv,y_test))
print('Error rate:', 1-clf.score(test_concat_mv,y_test))
SAXDist_train = np.array(SAXDist_train)
SAXDist_train.resize(y_train.shape[0],int(len(SAXDist_train)/y_train.shape[0]))
SAXDist_test = np.array(SAXDist_test)
SAXDist_test.resize(y_test.shape[0],int(len(SAXDist_test)/y_test.shape[0]))   
'''

#Feature concatenation

a = np.concatenate((PAA_test, SAX_test), axis=1)
b = np.concatenate((EDist_test, DTW_Classic_test, DTW_sakoe_test), axis=1)
test = np.concatenate((a, b), axis=1)

c = np.concatenate((PAA_train, SAX_train), axis=1)
d = np.concatenate((EDist_train, DTW_Classic_train, DTW_sakoe_train), axis=1)
train = np.concatenate((c, d), axis=1)

train_concat_mv = TimeSeriesScalerMeanVariance().fit_transform(train)
test_concat_mv = TimeSeriesScalerMeanVariance().fit_transform(test)

train_concat_mv.resize(train.shape[0], train.shape[1])
test_concat_mv.resize(test.shape[0], test.shape[1])

#SVM

clf = svm.SVC(gamma='scale')
clf.fit(train_concat_mv, y_train)

print(dataset)
print('Accuracy: ', clf.score(test_concat_mv, y_test))
                                        method='classic',
                                        return_path=True)
        DTW_Classic_train.append(dtw_classic)

DTW_Classic_train = np.array(DTW_Classic_train)
DTW_Classic_train.resize(y_train.shape[0],
                         int(len(DTW_Classic_train) / y_train.shape[0]))
DTW_Classic_test = np.array(DTW_Classic_test)
DTW_Classic_test.resize(y_test.shape[0],
                        int(len(DTW_Classic_test) / y_test.shape[0]))

train_concat_mv = TimeSeriesScalerMeanVariance().fit_transform(
    DTW_Classic_train)
test_concat_mv = TimeSeriesScalerMeanVariance().fit_transform(DTW_Classic_test)

train_concat_mv.resize(DTW_Classic_train.shape[0], DTW_Classic_train.shape[1])
test_concat_mv.resize(DTW_Classic_test.shape[0], DTW_Classic_test.shape[1])

#SVM

clf = svm.SVC(gamma='scale')
clf.fit(DTW_Classic_train, y_train)

print('Accuracy: ', clf.score(DTW_Classic_test, y_test))
#WEASEL
weasel_adiac = WEASEL(word_size=5, window_sizes=np.arange(6, X_train.shape[1]))

pipeline_adiac = Pipeline([("weasel", weasel_adiac), ("clf", clf)])

accuracy_adiac = pipeline_adiac.fit(X_train, y_train).score(X_test, y_test)