úterý 4. prosince 2018

Incremental learning feature-by-feature

Commonly, when we are training a model, we just use the data that are readily available and call it a day. But then there are "online" models that can be learned sample-by-sample. The advantage of these models is that they can be cheaply retrained as new data are observed. However, this post is about  models that can learn feature-by-feature, not by sample-by-sample.

What is the advantage of feature-by-feature learning? Sometimes, there is a cost associated with getting new measurements (features) for the given set of samples. And if all we want to do is to get a good enough classifier for the smallest possible cost, it makes sense to first try to build a model on a single feature, and keep adding new features until the model is good enough (or until we run out of money). The issue is that model training can be expensive. And if possible, we want to reuse calculations from the previous model in construction of the updated model. That is the core idea of incremental learning feature-by-feature.

Following paragraphs list common machine learning methods and how they can be modified for learning feature-by-feature.

Naive Bayes

Models that assume (conditional) independence of features support feature-by-feature learning by design. When a new feature arrives, we just calculate statistics on the feature and append the statistics to the model. An example of such model is naive Bayes. Limitations: naive Bayes has relatively small plasticity.

k-NN

In k-NN, all we have to do is to extend the training set by a feature. For small dimension count, branch-and-bound pruning can speed up scoring of the new samples. And to speed up the things even further, we do not have to calculate the distances with expensive metrices (e.g.: Euclidean distance). It is enough to select good candidates with inexpensive distances/similarities (e.g.: Jaccard similarity), prune the space, and only than calculate the expensive metric on the remaining samples. This is (approximately) the approach taken by Vector-Approximation file implementation.

Kernel methods

Kernel methods like SVM sometimes accept precomputed "similarity matrix" (e.g.: when dot product kernel is used, the matrix is called Gram matrix). And when a new feature appears, we update the similarity matrix. The update is approximately 6 times faster than calculation of the similarity matrix from scratch. Note that kernels can be used in other models beside SVM. To name just a few: logistic regression, perceptron, LDA and PCA. Till the similarity matrix fits the memory, all these methods are well suited for learning feature-by-feature. Note also that we have to remember the training data in order to score the new samples. Fortunately, SVM requires only support vectors, not all the training data. Unfortunately, after adding a new feature the set of support vectors may change. Hence, we still have to remember all the training data.

Decision tree

When we presort each tuple (feature, label) for each feature, the search for the optimal threshold gets accelerated. This is a common optimization, which is used for example in scikit decision tree. When a new feature appears, we just sort the new tuple and rebuild the tree. Furthermore, we can memoize the optimal threshold for the given path from the root to the current node - most of the time, the structure of the decision tree is not going to change when we add a new feature.

Random Forest/Extremely Randomized Trees/Boosted trees

Whenever a new feature appears, we just add a new tree into the ensemble. The only issue with RF and ERT is that newly added features have a chance to appear only in new trees, while old features can appear in both, old and new trees. Hence, older features are generally favored. To combat that, we may prefer newly added features in the new trees. Unfortunately, it does not fix the probability that two features appear in the same tree (it should be constant for any two features, but it isn't). A solution is to weight the trees with approximately 1.6^n, where n means the n-th tree in the ensemble. The advantage of this solution is that the weight of the old trees decays exponentially. Hence, once the ensemble grows too large to be practical (e.g.: the ensemble gets over 150 trees), we may simply drop the oldest tree whenever a new tree is generated without a large drop in accuracy.

Full Bayes

Assuming Bayes model that works with a single covariance matrix and a single vector of mean values, it is simple to update the matrix and the vector when a new feature is appears.







Žádné komentáře:

Okomentovat