def checkPredict(testX, testY): currentDataPoint = 0 driftCount = 0 totalPredictions = 0 correctPredictions = 0 currentError = 0 drift = False #Each model makes their own predicition testPredict1 = model1.predict(testX) testPredict2 = model2.predict(testX) testPredict3 = model3.predict(testX) testPredict4 = model4.predict(testX) for i in range(len(testY)): #final prediction is the average of all the models predictions prediction = (testPredict1[i] + testPredict2[i] + testPredict3[i] + testPredict4[i]) / 4 if (prediction >= (testY[currentDataPoint] * 0.98)): if (prediction <= (testY[currentDataPoint] * 1.02)): #if the prediction is correct tell the EDDM this drift = EDDM.set_input(True) correctPredictions = correctPredictions + 1 else: #if it prediction is wrong tell the EDDM this drift = EDDM.set_input(False) else: #if it prediction is wrong tell the EDDM this drift = EDDM.set_input(False) #If drift update counters if (drift): driftCount += 1 currentError += abs( (prediction - testY[currentDataPoint]) / testY[currentDataPoint]) currentDataPoint += 1 totalPredictions += 1 return totalPredictions, correctPredictions, driftCount, currentError
def checkPredict(testX, testY): currentDataPoint= 0 driftCount = 0 totalPredictions = 0 correctPredictions = 0 currentError = 0 #create test predictions testPredict = model.predict(testX) #loop through all the test predicitions and compare to actual results for y in testPredict: if(y >= (testY[currentDataPoint]*0.98)): if(y <= (testY[currentDataPoint]*1.02)): #if the prediction is correct tell the EDDM this drift = EDDM.set_input(True) correctPredictions += 1 else: #if it prediction is wrong tell the EDDM this drift = EDDM.set_input(False) else: #if it prediction is wrong tell the EDDM this drift = EDDM.set_input(False) if(drift): driftCount += 1 currentError += abs((y-testY[currentDataPoint])/testY[currentDataPoint]) currentDataPoint += 1 totalPredictions += 1 return totalPredictions, correctPredictions, driftCount, currentError
def checkPredict(startPoint, crct): currentDataPoint = startPoint driftCount = 0 totalPredictions = 0 correctPredictions = 0 currentError = 0 #create test predictions testPredict = model.predict(testX) drift = False driftPoint = 0 adjust = False currentCorrect = crct #loop through all the test predicitions and compare to actual results for i in range(currentDataPoint, len(testPredict)): if (testPredict[currentDataPoint] >= (testY[currentDataPoint] * 0.98)): if (testPredict[currentDataPoint] <= (testY[currentDataPoint] * 1.02)): #if the prediction is correct tell the EDDM this drift = EDDM.set_input(True) correctPredictions += 1 currentCorrect += 1 else: #if it prediction is wrong tell the EDDM this drift = EDDM.set_input(False) else: #if the prediction is wrong tell the EDDM this drift = EDDM.set_input(False) #if Drift is detected and window size isn't 2 stop checking and change window size and retrain if (drift): driftCount += 1 driftPoint = currentDataPoint + 1 currentCorrect = 0 if (look_back > 2): currentError += abs( (testPredict[currentDataPoint] - testY[currentDataPoint]) / testY[currentDataPoint]) totalPredictions += 1 return totalPredictions, correctPredictions, driftCount, currentCorrect, drift, adjust, currentError #if 30 correct predictions sctop prediciting and change window size back to original if (currentCorrect > 30): currentCorrect = 0 if (look_back != 10): currentError += abs( (testPredict[currentDataPoint] - testY[currentDataPoint]) / testY[currentDataPoint]) totalPredictions += 1 driftPoint = currentDataPoint + 1 adjust = True return totalPredictions, correctPredictions, driftCount, currentCorrect, drift, adjust, currentError currentError += abs( (testPredict[currentDataPoint] - testY[currentDataPoint]) / testY[currentDataPoint]) currentDataPoint += 1 totalPredictions += 1 #Or return total amount of predictions made, correct predicitions made, amount of drifts detected, how many are currently correct, if there is a drift, if the window needs to be adjusted, and the current percent error return totalPredictions, correctPredictions, driftCount, currentCorrect, drift, adjust, currentError
global totalTrainRMSE global totalTestRMSE totalTestRMSE = 0 totalTrainRMSE = 0 os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # fix random seed for reproducibility numpy.random.seed(7) # load the dataset, Change DATASET.csv to the file you want to load, change usecols=[0] to correct coloumn for the dataset dataframe = pandas.read_csv('DATASET.csv', usecols=[0], engine='python', skipfooter=3) dataset = dataframe.values dataset = dataset.astype('float32') EDDM = EDDM() driftCount = 0 drift = False # convert an array of values into a dataset matrix def create_dataset(dataset, end, start): dataX, dataY = [], [] for i in range(start, end - look_back): dataX.append(dataset[i:(i + look_back), 0]) for i in range(start + look_back, end): dataY.append(dataset[i, 0]) return numpy.array(dataX), numpy.array(dataY) #create datasets