This is documentation for Orange 2.7. For the latest documentation, see Orange 3.

Classification (classification)

Induction of models in Orange is implemented through a two-class schema. A learning algorithm is represented by an instance of a class derived from Orange.classification.Learner. The learner stores all parameters of the learning algorithm. Induced models are represented by instances of classes derived from Orange.classification.Classifier.

Therefore, to induce models from data, one first needs to construct the instance representing a learning algorithm (e.g. TreeLearner) and set its parameters. Calling the learner with some training data returns a classifier (e.g. TreeClassifier). The learner does not “learn” to classify but constructs classifiers.

import Orange
titanic = Orange.data.Table("titanic.tab")

learner = Orange.classification.bayes.NaiveLearner()
classifier = learner(titanic)

for inst in titanic[:5]:
    print inst.getclass(), classifier(inst)

To simplify the procedure, the learner’s constructor can also be given training data, in which case it fits and returns a model (an instance of Classifier) instead of a learner:

classifier = Orange.classification.bayes.NaiveLearner(titanic)

Orange contains a number of learning algorithms described in detail on separate pages.

All learning algorithms and prediction models are derived from the following two clases.

class Orange.classification.Learner

Abstract base class for learning algorithms.

__call__(data[, weightID])

An abstract method that fits a model and returns it as an instance of Classifier. The first argument gives the data (as Orange.data.Table and the optional second argument gives the id of the meta attribute with instance weights.

class Orange.classification.Classifier

Abstract base class for prediction models (both classifiers and regressors).

__call__(instance, return_type=GetValue)

Classify a new instance using this model. Results depends upon the second parameter that must be one of the following.

Orange.classification.Classifier.GetValue

Return value of the target class when performing prediction.

Orange.classification.Classifier.GetProbabilities

Return probability of each target class when performing prediction.

Orange.classification.Classifier.GetBoth

Return a tuple of target class value and probabilities for each class.
Parameters:
  • instance (Instance) – data instance to be classified.
  • return_type (GetBoth, GetValue, GetProbabilities) – what needs to be predicted
Return type:

Value, Distribution or a tuple with both