def _run_method(method, X, y, train, test): """ Train the `method` on X[train] and test on X[test]. """ clf = run_delayed(method) start = time() clf.fit(X[train], y[train]) accs = clf.score(X[test], y[test]) wall = time() - start return accs, wall
job_batchsize = int(J / n_jobs) a = args.j * job_batchsize b = a + job_batchsize if (args.j < n_jobs-1) else J # Get cross-validation folds cv = LeaveOneOut(n) if (args.k == 0) else KFold(n, args.k) if not args.a: # Setup list of jobs jobs = iter(delayed(run_method)(method, X, y, train, test, force=args.f) for method, (train, test) in itertools.product(methods, cv)) # Run only jobs in batch for job in itertools.islice(jobs, a, b): run_delayed(job) else: # Aggregate results accs = np.empty(M * args.k) wall = np.empty(M * args.k) accs.fill(np.nan) wall.fill(np.nan) # Fetch data jobs = iter(delayed(run_method)(method, X, y, train, test, load=True) for method, (train, test) in itertools.product(methods, cv)) for i, job in enumerate(jobs): accs[i], wall[i] = run_delayed(job) accs.resize((M, args.k)) wall.resize((M, args.k))