Esempio n. 1
0
# Bin time, get firing rates with history in previous bins
T, X = process_clustered_signal_data(data['signal_times'], data['signal_cellids'],
                                        temporal_bin_size=0.5,
                                        bins_before=2,
                                        bins_after=2,
                                        flatten_history=True)
# Get stimulusv alues at spike times
y = stimulus_at_times(stimulus_times, stimulus_data, T)

# Get scores and display for each estimator
results = {}
for name, estimator in ESTIMATORS.items():
    print('[{}] Starting...'.format(name))
    pipeline = make_pipeline(StandardScaler(), estimator)

    cv = generate_crossvalidator(pipeline, X, y, training_mask=None, n_splits=N_FOLDS)

    # Use the convenient cross_validate function to score
    results[name] = cross_validate(pipeline, X, y, scoring=SCORERS, cv=cv, return_train_score=True)

    fit_time = results[name]['fit_time']
    score_time = results[name]['score_time']

    print('[{}] Fit time {:.4} +- {:.2} | Score time {:.4} +- {:.2}'.format(name,
        np.mean(fit_time), np.std(fit_time), np.mean(score_time), np.std(score_time)))
    
    for scorer in SCORERS:
        test_score = results[name]['test_' + scorer]
        train_score = results[name]['train_' + scorer]
        print ('[{}] {}: Test score {:.4} +- {:.2} | Train score {:.4} +- {:.2}'.format(name,
            scorer, np.mean(test_score), np.std(test_score), np.mean(train_score), np.std(train_score)))
Esempio n. 2
0
# Convert the pipeline to support multiple signals
# Filter to combine the signals
estimator = MultisignalEstimator(
    signal_pipeline,
    filt=TemporalSmoothedFilter(bandwidth_T=2.5 * RESOLUTION,
                                std_deviation=10,
                                n_jobs=8),
    pickle_estimators=False,
    pickler_kwargs=dict(save_location='/run/media/mz/data/.mlneuro/tmp/'))

# Create a cross-validator object that
#   Limits the training set to a subset of the full data
#   Splits the data into K "folds"
cv = generate_crossvalidator(estimator,
                             Xs,
                             ys,
                             training_mask=y_train_masks,
                             n_splits=N_FOLDS)

# Run the prediction cross-validated (method='predict_proba' by default)
T_pred, (y_pred,
         y_test) = cross_val_predict_multisignal(estimator,
                                                 Xs,
                                                 ys,
                                                 Ts,
                                                 filter_times=RESOLUTION,
                                                 cv=cv,
                                                 n_jobs=1)

# Normalize to a probability distribution
y_pred /= np.sum(y_pred, axis=1)[:, np.newaxis]
    ([bandwidth_features] * len(FEATURE_SUBSET)) + [bandwidth_cellids],
    dtype=np.float64)

# Construct the KDE
estimator = BivariateKernelDensity(n_neighbors=30,
                                   bandwidth_X=0.13,
                                   bandwidth_y=12,
                                   ybins=ybin_edges,
                                   tree_backend='auto' if GPU else 'ball',
                                   n_jobs=8,
                                   logger_level='debug')

# Create a cross-validator object
cv = generate_crossvalidator(estimator,
                             X,
                             y,
                             training_mask=y_train_mask,
                             n_splits=N_FOLDS,
                             limit_training_size=0.35)

# Run the prediction cross-validated and get probabilties
# Notice, `pickle_predictions` is set which will write predictions to disk each fold to make space in memory
#   for computations
y_pred = cross_val_predict(estimator,
                           X,
                           y,
                           cv=cv,
                           n_jobs=1,
                           method='predict_proba',
                           pickle_predictions=True)

# Filter the data