Random Classifier

Random classifier (class RandomClassifier)disregards the examples and returns random predictions. Curious enough though, the classifier will always predict the same class for the same example. Predictions can be distributed by the prescribed distribution.

Attributes

probabilites
Distribution of probabilities for the classifier.

To verify this miraculous classifier, we shall classify the first ten examples from lenses dataset for three times.

random_classifier.py (uses lenses.tab)

import orange, orngTest, orngStat data = orange.ExampleTable("lenses") rc = orange.RandomClassifier() rc.classVar = data.domain.classVar rc.probabilities = [0.5, 0.3, 0.2] for i in range(3): for ex in data[:5]: print ex, rc(ex) print

The script always prints

['young', 'myope', 'no', 'reduced', 'none'] none ['young', 'myope', 'no', 'normal', 'soft'] soft ['young', 'myope', 'yes', 'reduced', 'none'] none ['young', 'myope', 'yes', 'normal', 'hard'] soft ['young', 'hypermetrope', 'no', 'reduced', 'none'] none

Setting classVar is needed for nicer output. Remove it and see what happens.

OK, how does this really work? Random classifier computes the hash value of example (equivalent to calling hash(ex), where hash is a Python's built-in function), masks it by 0x7fffffff and divides it by 0x7fffffff to get a floating point number between 0 and 1. This value's position in the distribution determines the class. In our example, random values below 0.5 give the first class, those between 0.5 and 0.8 give the second and the rest give the third.

Random Learner

RandomLearner returns the above classifier.

Attributes

probabilites
Distribution of probabilities for the classifier. If not given, the learner will use the class distribution from the training data.