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.
- 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.GetValueReturn value of the target class when performing prediction.
Orange.classification.Classifier.GetProbabilitiesReturn probability of each target class when performing prediction.
Orange.classification.Classifier.GetBothReturn a tuple of target class value and probabilities for each class.
- instance (Instance) – data instance to be classified.
- return_type (GetBoth, GetValue, GetProbabilities) – what needs to be predicted