コード例 #1
0
ファイル: sim_adwin.py プロジェクト: thanapol2/data_stream
def sim_ddm(input_stream, start_point=0):
    ddm = DDM()
    change_point = []
    detected_warning = []
    for i in range(len(input_stream)):
        ddm.add_element(input_stream[i])
        if ddm.detected_warning_zone():
            detected_warning.append(i + start_point)
        if ddm.detected_change():
            # plt.axvline(i, color='r', linestyle='dashed')
            change_point.append(i + start_point)
            # print('Change detected in data: ' + str(input_stream[i]) + ' - at index: ' + str(i)+'\n\n')

    return detected_warning, change_point
コード例 #2
0
ファイル: ddm.py プロジェクト: farnaz2018/NLP-Project
def ddm_test():
    ddm = DDM()
    true_occur_position = 4443
    data_stream = np.load("data/stream_acc.npy")
    for i in tqdm(range(data_stream.shape[0])):
        # print(data_stream[i])
        # print(i)
        ddm.add_element(data_stream[i])
        if ddm.detected_warning_zone():
            print('Warning zone has been detected in data: ' +
                  str(data_stream[i]) + ' - of index: ' + str(i))
        if ddm.detected_change():
            print('Change has been detected in data: ' + str(data_stream[i]) +
                  ' - of index: ' + str(i))
コード例 #3
0
        if (n_global > detect_end):
            if ht_p is not None:
                drift_point = detect_end - 2 * grace
                print("Accuracy of ht: " + str(np.mean(pred_grace_ht)))
                print("Accuracy of ht_p: " + str(np.mean(pred_grace_ht_p)))
                if (np.mean(pred_grace_ht_p) > np.mean(pred_grace_ht)):
                    print("TP detected at: " + str(drift_point))
                    TP_ddm.append(drift_point)
                    ht = ht_p
                else:
                    print("FP detected at: " + str(drift_point))
                    FP_ddm.append(drift_point)
                ht_p = None
                pred_grace_ht = []
                pred_grace_ht_p = []
            if ddm.detected_warning_zone():
                w_ddm += 1
            if ddm.detected_change():
                d_ddm += 1
                ht_p = HoeffdingTreeClassifier()
                grace_end = n_global + grace
                detect_end = n_global + 2 * grace
        else:
            pred_grace_ht.append(y_test == y_predict)
            pred_grace_ht_p.append(y_test == ht_p.predict(X_test))

    if ht_p is not None:
        ht_p.partial_fit(X_test, y_test)
    ht.partial_fit(X_test, y_test)
    if n_global % 10000 == 0:
        # For Travis CI