I am working on a classification problem, where I have sequences of images and I want to train a model to predict the index of the image with some wanted property.
The target classes would obviously be the possible indices of images, hence for a sequences of lets say n=100
images, I have 100 possible target classes. Does it still make sense to model this as a classification problem, or can one already see it as a regression with continuous values?
More generally speaking, how many target classes make a problem more like a regression than a classification?
1 Answer
What number classes makes a classification problem continuous
There is no such number. First you should figure out whether your core problem is regression or classification (or in some cases something in-between such as predicting the year of a recording from the audio). However, you may decide to switch techniques around when number of classes is high.
Classification and regression problems are conceptually separate.
If your classes can be strictly ordered, and classes next to each other can be considered usefully "close", in that incorrect classification that is out by one or two places is somehow better than incorrect classification of a more "distant" class, then you may have a case which usefully transforms between a classification and regression problem. There will be no fixed number that decides this. Instead what you should do is decide on a success metric (e.g. accuracy or relative error) for measuring how well the machine learning is performing. Then you should try both classification-based models and regression-based models (maybe with rounding, if you strictly need a class prediction), deciding on which one to use depending on the score at the metric.
Your image classifier might be like this if the images can be meaningfully ordered with respect to what is being predicted. For instance, if these were slices through a 3D shape, and you wanted to predict where a new image would be positioned parallel to them within a similar shape. Or if the images represented views of landscapes taken at different times of the year, and you wanted to predict an approximate date for a new image. If this is the case, then using a regression model, maybe with rounding, could work well.
Otherwise, as your number of image types increases, you may want to switch from a simple classifier to something more like an identifier, such as used in face recognition. Identifiers are regression models that are trained to extract non-changing traits from data that may be arbitrary, but specifically differentiate between classes. Typically these are trained using triplet loss on pairs of same vs different items, with the goal being to learn and assign arbitrary vectors to images based on identity. The classification is then performed outside the neural network, based on distance between an output vector and a number of stored vectors of pre-processed images. This approach can differentiate between thousands of target classes, and also can deal with changes to the target classes without re-training.
If neither of the above apply, then you might be able to try other approaches, such as grouping classes into heirarchies, if that applies, and predicting broader class membership first. Or you could simply have a large number of output classes. Deep Mind's Alpha Go predicts 361 classes for position to play in. The LLM models behind ChatGPT predict between 1000s of token classes.
In all cases, you should try to determine a metric in advance - what results would show you have the best model? Then you can try the different approaches and be able to choose between them.