accuracy_1 = true_predictions_1 / total accuracy_2 = true_predictions_2 / total accuracy_3_mv = true_predictions_3_mv / total accuracy_3_av = true_predictions_3_av / total accuracy_3_goowe = true_predictions_3_goowe / total print('\tSTREAM 1 :: Data instance: {} - Accuracy: {}'.format(int(total), round(accuracy_1*100.0, 3))) print('\tSTREAM 2 :: Data instance: {} - Accuracy: {}'.format(int(total), round(accuracy_2*100.0, 3))) print('\tSTREAM 3 :: Data instance: {} - Accuracies: MV: {} - AV: {} - Goowe: {}'.format(int(total), round(accuracy_3_mv*100.0, 3), round(accuracy_3_av*100.0, 3), round(accuracy_3_goowe*100.0, 3))) print('\t==========================================================================') goowe_1.partial_fit(X_1, y_1) goowe_2.partial_fit(X_2, y_2) goowe_3.update(X_3, y_3, 1, 1) # Now, for the remaining instances, do ITTT (Interleaved Test Then Train). while(stream_1.has_more_samples() and stream_2.has_more_samples() and stream_3.has_more_samples() and instances_counter < instances_num): if(instances_counter % CHUNK_SIZE == 0): accuracy_1 = 0.0 total_1 = 0.0 true_predictions_1 = 0.0 accuracy_2 = 0.0 total_2 = 0.0 true_predictions_2 = 0.0 accuracy_3_mv = 0.0 accuracy_3_av = 0.0 accuracy_3_goowe = 0.0 total_3 = 0.0 true_predictions_3_mv = 0.0 true_predictions_3_av = 0.0 true_predictions_3_goowe = 0.0
from skmultiflow.data import SEAGenerator from skmultiflow.meta import AdaptiveRandomForestClassifier stream = SEAGenerator(random_state=1) # Setup Adaptive Random Forest Classifier arf = AdaptiveRandomForestClassifier() # Setup variables to control loop and track performance n_samples = 0 correct_cnt = 0 max_samples = 1200 # Train the estimator with the samples provided by the data stream while n_samples < max_samples and stream.has_more_samples(): X, y = stream.next_sample() y_pred = arf.predict(X) if y[0] == y_pred[0]: correct_cnt += 1 arf.partial_fit(X, y) n_samples += 1 # Display results print('Adaptive Random Forest ensemble classifier example') print('{} samples analyzed.'.format(n_samples)) print('Accuracy: {}'.format(correct_cnt / n_samples))