Source

orange-multitask / tests / test_groups.py

import Orange
from Orange.multitask import MultiTaskLearner, mtfeat

import generate_data


groups, pergroup, tasks, overlap = 10, 10, 10, 2
factors = [3,2,1,1,1]
data = generate_data.Group(groups, pergroup, factors, tasks, overlap=overlap)(pertask=50)

mean = Orange.regression.mean.MeanLearner()
mtmean = MultiTaskLearner(learner=mean)
ridge = Orange.regression.linear.LinearRegressionLearner(ridge_lambda=4)
mtridge = MultiTaskLearner(learner=ridge)
mtf = mtfeat.MTFeatLearner(max_iter=50, gamma=3., intercept=True, tol=1e-7)
mtfs = mtfeat.MTFeatLearner(max_iter=50, gamma=0.1, selection=True, intercept=True, tol=1e-7)
mtfg = mtfeat.MTFeatLearner(max_iter=50, gamma=0.1, intercept=True, tol=1e-7, groups=[
    range(i * (pergroup - overlap), (i + 1) * pergroup - i * overlap)
    for i in range(groups)])

learners = [mean, mtmean, ridge, mtridge, mtfs, mtf, mtfg]
res = Orange.evaluation.testing.cross_validation(learners, data, folds=4, store_classifiers=1)
print Orange.evaluation.scoring.RMSE(res)