# Incremental learning for classification models in R

Assume, I have a classifier (It could be any of the standard classifiers like decision tree, random forest, logistic regression .. etc.) for fraud detection using the below code

library(randomForest)
rfFit = randomForest(Y ~ ., data = myData, ntree = 400) # A very basic classifier


Say, Y is a binary outcome - Fraud/Not-Fraud

Now, I have predicted on a unseen data set.

pred = predict(rfFit, newData)


Then I have obtained the feedback from the investigation team on my classification and found that I have made a mistake of classifying a fraud as Non-Fraud (i.e. One False Negative). Is there anyway that I can let my algorithm understand that it has made a mistake? i.e. Any way of adding a feedback loop to the algorithm so that it can correct the mistakes?

One option I can think from top of my head is build an adaboost classifier so that the new classifier corrects the mistake of the old one. or I have heard something of Incremental Learning or Online learning. Are there any existing implementations (packages) in R?

Is it the right approach? or Is there any other way to tweak the model instead of building it from the scratch?

• Did you find a solution? I have the same issue. – Blu3nx Sep 8 '17 at 7:38
• @Blu3nx please do not use answers for commenting questions. Answers are meant to answering them. – Tim Sep 8 '17 at 8:08
• Not an answer, but what's stopping you from just going myData\$Fraud[positionofincorrectvariable] = Correct Value? – Tilefish Poele Sep 8 '17 at 8:57

A boosting strategy may improve the performance of your model, so it is worth a try. With respect to incremental/online learning, I am not aware of any package in R that implements it (others, please correct me if I am wrong). In Scikit Learn, there are out-of-core classifiers that allow for incremental learning. However, if you are tied to using R, you may have no choice but to write your own incremental model. In either case, looking into Scikit Learn's out-of-core classifiers may give you an idea of where to start.

Another detail to keep in mind is the extent to which updating the model on a single false positive or false negative will improve the model's performance. In the domain of fraud, there are generally thousands to millions of times more instances of non-fraud then fraud. As such, it is important to try to learn to discriminate every fraud instance correctly, but updating a model on a single fraud instance will likely not change the model significantly. Consider other strategies for getting the model to attribute more significance to fraud instances.

The most straightforward way of improving your supervised model, based on feedback from human investigators would be to build a separate model from the corrected instances (i.e. the instances predicted incorrectly that were after properly labeled). You could then have your two models "vote" on the classification of future instances by aggregating their predicted class memberships. For instance, ModelA may believe Instance1 is [Fraud: 0.65, Non-Fraud: 0.35], while ModelB believes Instance1 is [Fraud: 0.47, Non-Fraud: 0.53]. The prediction of the ensemble would thus be [Fraud: (0.65+0.47)/2=0.56, Non-Fraud: (0.35+0.53)/2=0.44].

If your original model is performing better than chance, the number of instances it correctly classifies will be greater than the number incorrectly classified. Thus, you do not want to attribute equal weight to the models if they are trained on a disproportionate number of instances. There are two straightforward options to handle this disparity: 1) wait until you accumulate enough corrected instances to approximately equal the number the original model was trained on, or 2) assign weight to each model based upon how the model performs on a validation set.

I did some research in the past about online and incremental learning. There are some ideas you need to take into account.

Every classifier can 'do' incremental learning, the only problem is that with some is much more harder to do so. There is not an incremental learning algorithm as such, only a way of achieving this buy using the common algorithms. Normally, you would pick one of them and adapt the way you train it and feed the data either in a batch or in an online fashion.

You can do this in two ways: a) Retrain the model from scratch each time a new sample (or set of samples) arrive. Obviously this is not ideal, but if your model is not too complex (meaning yo can perform a whole training between instances coming) and you limit your dataset size (discarding old data, new data or random data and keeping a steady number of training instances), it can work in some scenarios. A nice example of this 'pseudo-incremental' learning with support vector machines can be found here.

b) Find a way to update your model parameters/weights by only modifying 'a little bit' these parameters when the prediction was wrong. Neural Nets are naturally great for this as you can train a model, save the weights and then retrain with new batches of data as they come. Additionally, you can tweak the learning rate to give more/less relevance to your new inputs. If you can choose any algorithm for your case, this would be my choice. However, there are many other methods: e.g. in Bayesian approaches you can modify the distributions applying numerical increments/decrements to certain parameters (see this for another example.)

Do some reading and look for previous approaches that match whatever you want your learning algorithm behaviour. It can seem daunting in the beginning to set everything up for yourself instead of using this or that library, but it becomes supercool when you arrive to the point you feel in charge of all the learning process of your model.

Good luck!