import time

from manifold.learning import algorithms
from manifold.infrastructure import Retriever, Displayer

TITLE = '3. Breast-cancer'


def main():
    print(TITLE)

    r = Retriever('../datasets/breast-cancer/wdbc.data', delimiter=',')

    # Remove ids, as they are not correlated in any way with the target feature.
    r.split_column(0)

    # Split target from data and retrieve both.
    # Target feature is actually located in the 2nd column, but considering we
    # had the ids removed, it's now in the 1st one.
    data, diagnosis = r.split_target(0).retrieve()
    data = data.astype(float)

    start = time.time()
    reduced_data = algorithms.Isomap(data, k=4).run()
    elapsed = time.time() - start

    Displayer(tite=TITLE) \
        .load('Original data-set', data, diagnosis) \
        .load('Isomap (%ss)' % (elapsed / 1000), reduced_data, diagnosis) \
        .render()


if __name__ == '__main__':
    main()

@@ -4,16 +4,77 @@
 ort time
+%0Aimport multiprocessing%0A%0Afrom sklearn import grid_search, svm
 %0A%0Afrom m
@@ -663,16 +663,121 @@
 float)%0A%0A
+    d = Displayer(tite=TITLE).load('Original data-set', data, diagnosis)%0A%0A    learn(data, diagnosis, d)%0A%0A
     star
@@ -884,184 +884,667 @@
 art%0A
-%0A
     
-Displayer(tite=TITLE) %5C%0A        .load('Original data-set', data, diagnosis) %5C%0A        .load('Isomap (%25ss)' %25 (elapsed / 1000), reduced_data, diagnosis) %5C%0A        .render()
+d.load('Isomap (%25ss)' %25 (elapsed / 1000), reduced_data, diagnosis)%0A%0A    learn(reduced_data, diagnosis, d)%0A%0A    d.render()%0A%0A%0Adef learn(data, target, d):%0A    start = time.time()%0A    print('GridSearch started at %25s...' %25 start)%0A%0A    param_grid = %7B%0A        'C': (10, 100, 1000),%0A        'gamma': (0.01, 0.1, 1),%0A        'kernel': ('linear',),%0A    %7D%0A%0A    clf = grid_search.GridSearchCV(svm.SVC(), param_grid, n_jobs=multiprocessing.cpu_count())%0A    clf.fit(data, target)%0A%0A    print('%5CtAccuracy: %25.2f%25%25%5Cn'%0A          '%5CtTime elapsed: %25.0fs%5Cn'%0A          '%5CtBest parameters: %25s'%0A          %25 (clf.best_score_, time.time() - start, clf.best_params_))%0A%0A    return clf
 %0A%0A%0Ai

Update 3.breast_cancer Perform GridSearch and learn over breast_cancer data set before and after learning the manifold.