@@ -0,0 +1,2715 @@
+import numpy as np%0Afrom math import log10%0Aimport pylab as pl%0Aimport os%0A%0A%0Adef compute_score(model, data_file, index, train_size, permutation):%0A    from sklearn.externals import joblib%0A    (X, y) = joblib.load(data_file, mmap_mode='r')%0A%0A    Xtrain = X%5Bpermutation%5B:train_size%5D, :%5D%0A    ytrain = y%5Bpermutation%5B:train_size%5D, :%5D%0A    Xtest  = X%5Bpermutation%5Btrain_size:%5D, :%5D%0A    ytest  = y%5Bpermutation%5Btrain_size:%5D, :%5D%0A%0A    model.fit(Xtrain, ytrain)%0A    score_train = model.score(Xtrain, ytrain)%0A    score_test  = model.score(Xtest,  ytest)%0A    return (index, score_train, score_test)%0A%0A%0Aclass LearningCurve:%0A    def __init__(self, lb_view, model, X, y, resolution=20, cv_folds=5,%0A                    dump_folder='dumps/splits'):%0A        from sklearn.externals import joblib%0A        self.resolution = resolution%0A        self.lb_view = lb_view%0A%0A        set_size         = X.shape%5B0%5D%0A        test_size        = set_size/cv_folds%0A        max_train_size   = set_size - test_size%0A        self.train_sizes = np.logspace(2, log10(max_train_size), self.resolution).astype(np.int)%0A        permutations     = %5Bnp.random.permutation(set_size) for i in xrange(cv_folds)%5D%0A%0A        self.tasks  = %5B%5D%0A%0A        data_file = os.path.join(dump_folder, %22learningcurve.pkl%22)%0A        joblib.dump((X, y), data_file)%0A%0A        for i, train_size in enumerate(self.train_sizes):%0A            for permutation in permutations:%0A                task = self.lb_view.apply(compute_score, model, data_file,%0A                                            i, train_size, permutation)%0A                self.tasks.append(task)%0A%0A%0A    def progress(self):%0A        ready = sum(%5B1 for task in self.tasks if task.ready()%5D)%0A        print %22%25i%25%25%22 %25 (100*ready / len(self.tasks))%0A%0A    def wait(self):%0A        for task in self.tasks:%0A            self.lb_view.wait(task)%0A%0A    def get_scores(self):%0A        scores_train = %5B%5B%5D for i in xrange(self.resolution)%5D%0A        scores_test  = %5B%5B%5D for i in xrange(self.resolution)%5D%0A%0A        for task in self.tasks:%0A            if not task.ready(): %0A                continue%0A%0A            index, score_train, score_test = task.get()%0A            scores_train%5Bindex%5D.append(score_train)%0A            scores_test%5Bindex%5D.append(score_test)%0A%0A        return (self.train_sizes, %5Bnp.mean(score) for score in scores_train%5D, %0A                             %5Bnp.mean(score) for score in scores_test%5D)%0A%0A    def plot(self):%0A        sizes, scores_train, scores_test = self.get_scores()%0A        pl.plot(sizes, scores_train, 'o-k', c='g', label='Train Score')%0A        pl.plot(sizes, scores_test, 'o-k', c='b', label='Test Score')%0A        pl.xlabel(%22Training set size%22)%0A        pl.ylabel(%22Score%22)%0A        pl.legend(loc='best')%0A        pl.title(%22Learning Curve%22)%0A%0A%0A

Add 'learning_curve' module