-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
565 changed files
with
116,174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: b8cc9f9a7a49cac039167958d5de865e | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Binary file not shown.
Binary file added
BIN
+96.7 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.PipelineCreator.doctree
Binary file not shown.
Binary file added
BIN
+25.1 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.TargetPipelineCreator.doctree
Binary file not shown.
Binary file added
BIN
+21.2 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.ColumnTypes.doctree
Binary file not shown.
Binary file added
BIN
+7.99 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.ColumnTypesLike.doctree
Binary file not shown.
Binary file added
BIN
+35.3 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.JuBaseEstimator.doctree
Binary file not shown.
Binary file added
BIN
+59.1 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.JuTransformer.doctree
Binary file not shown.
Binary file added
BIN
+64.7 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.WrapModel.doctree
Binary file not shown.
Binary file added
BIN
+9.44 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.change_column_type.doctree
Binary file not shown.
Binary file added
BIN
+8.56 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.ensure_column_types.doctree
Binary file not shown.
Binary file added
BIN
+8.38 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.get_column_type.doctree
Binary file not shown.
Binary file added
BIN
+9.06 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.base.make_type_selector.doctree
Binary file not shown.
Binary file added
BIN
+15.9 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.inspect.FoldsInspector.doctree
Binary file not shown.
Binary file added
BIN
+31.3 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.inspect.Inspector.doctree
Binary file not shown.
Binary file added
BIN
+23.8 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.inspect.preprocess.doctree
Binary file not shown.
Binary file added
BIN
+52.8 KB
...76/.doctrees/api/generated/julearn.model_selection.ContinuousStratifiedGroupKFold.doctree
Binary file not shown.
Binary file added
BIN
+47.5 KB
.../pr-276/.doctrees/api/generated/julearn.model_selection.ContinuousStratifiedKFold.doctree
Binary file not shown.
Binary file added
BIN
+40.5 KB
...rees/api/generated/julearn.model_selection.RepeatedContinuousStratifiedGroupKFold.doctree
Binary file not shown.
Binary file added
BIN
+39.9 KB
....doctrees/api/generated/julearn.model_selection.RepeatedContinuousStratifiedKFold.doctree
Binary file not shown.
Binary file added
BIN
+43 KB
...review/pr-276/.doctrees/api/generated/julearn.model_selection.StratifiedBootstrap.doctree
Binary file not shown.
Binary file added
BIN
+9.42 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.model_selection.get_searcher.doctree
Binary file not shown.
Binary file added
BIN
+7.63 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.model_selection.list_searchers.doctree
Binary file not shown.
Binary file added
BIN
+14.3 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.model_selection.register_searcher.doctree
Binary file not shown.
Binary file added
BIN
+6.64 KB
...ew/pr-276/.doctrees/api/generated/julearn.model_selection.reset_searcher_register.doctree
Binary file not shown.
Binary file added
BIN
+63.3 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.models.dynamic.DynamicSelection.doctree
Binary file not shown.
Binary file added
BIN
+10.7 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.models.get_model.doctree
Binary file not shown.
Binary file added
BIN
+7.17 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.models.list_models.doctree
Binary file not shown.
Binary file added
BIN
+16.4 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.models.register_model.doctree
Binary file not shown.
Binary file added
BIN
+6.4 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.models.reset_model_register.doctree
Binary file not shown.
Binary file added
BIN
+35.3 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.pipeline.JuTargetPipeline.doctree
Binary file not shown.
Binary file added
BIN
+39 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.pipeline.pipeline_creator.Step.doctree
Binary file not shown.
Binary file added
BIN
+12.7 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.prepare.check_consistency.doctree
Binary file not shown.
Binary file added
BIN
+19.7 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.prepare.prepare_input_data.doctree
Binary file not shown.
Binary file added
BIN
+126 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.run_cross_validation.doctree
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+9.87 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.scoring.check_scoring.doctree
Binary file not shown.
Binary file added
BIN
+9.1 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.scoring.get_scorer.doctree
Binary file not shown.
Binary file added
BIN
+10.5 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.scoring.list_scorers.doctree
Binary file not shown.
Binary file added
BIN
+9.48 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.scoring.metrics.r2_corr.doctree
Binary file not shown.
Binary file added
BIN
+9.4 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.scoring.metrics.r_corr.doctree
Binary file not shown.
Binary file added
BIN
+17.4 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.scoring.register_scorer.doctree
Binary file not shown.
Binary file added
BIN
+6.37 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.scoring.reset_scorer_register.doctree
Binary file not shown.
Binary file added
BIN
+25.4 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.stats.corrected_ttest.doctree
Binary file not shown.
Binary file added
BIN
+72.6 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.CBPM.doctree
Binary file not shown.
Binary file added
BIN
+68.9 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.ChangeColumnTypes.doctree
Binary file not shown.
Binary file added
BIN
+65.7 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.DropColumns.doctree
Binary file not shown.
Binary file added
BIN
+66.8 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.FilterColumns.doctree
Binary file not shown.
Binary file added
BIN
+74.7 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.JuColumnTransformer.doctree
Binary file not shown.
Binary file added
BIN
+67.5 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.SetColumnTypes.doctree
Binary file not shown.
Binary file added
BIN
+81.1 KB
...276/.doctrees/api/generated/julearn.transformers.confound_remover.ConfoundRemover.doctree
Binary file not shown.
Binary file added
BIN
+9.67 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.get_transformer.doctree
Binary file not shown.
Binary file added
BIN
+7.43 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.list_transformers.doctree
Binary file not shown.
Binary file added
BIN
+14.7 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.transformers.register_transformer.doctree
Binary file not shown.
Binary file added
BIN
+6.58 KB
...ew/pr-276/.doctrees/api/generated/julearn.transformers.reset_transformer_register.doctree
Binary file not shown.
Binary file added
BIN
+23.1 KB
...ew/pr-276/.doctrees/api/generated/julearn.transformers.target.JuTargetTransformer.doctree
Binary file not shown.
Binary file added
BIN
+67.1 KB
...-276/.doctrees/api/generated/julearn.transformers.target.JuTransformedTargetModel.doctree
Binary file not shown.
Binary file added
BIN
+33.7 KB
.../pr-276/.doctrees/api/generated/julearn.transformers.target.TargetConfoundRemover.doctree
Binary file not shown.
Binary file added
BIN
+11.7 KB
...-276/.doctrees/api/generated/julearn.transformers.target.TransformedTargetWarning.doctree
Binary file not shown.
Binary file added
BIN
+10.7 KB
...pr-276/.doctrees/api/generated/julearn.transformers.target.get_target_transformer.doctree
Binary file not shown.
Binary file added
BIN
+7.97 KB
...-276/.doctrees/api/generated/julearn.transformers.target.list_target_transformers.doctree
Binary file not shown.
Binary file added
BIN
+14.7 KB
...6/.doctrees/api/generated/julearn.transformers.target.register_target_transformer.doctree
Binary file not shown.
Binary file added
BIN
+6.95 KB
...trees/api/generated/julearn.transformers.target.reset_target_transformer_register.doctree
Binary file not shown.
Binary file added
BIN
+64.5 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.configure_logging.doctree
Binary file not shown.
Binary file added
BIN
+5.6 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.logger.doctree
Binary file not shown.
Binary file added
BIN
+9.87 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.raise_error.doctree
Binary file not shown.
Binary file added
BIN
+7.42 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.typing.EstimatorLike.doctree
Binary file not shown.
Binary file added
BIN
+21.8 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.typing.EstimatorLikeFit1.doctree
Binary file not shown.
Binary file added
BIN
+21.8 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.typing.EstimatorLikeFit2.doctree
Binary file not shown.
Binary file added
BIN
+19.9 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.typing.EstimatorLikeFity.doctree
Binary file not shown.
Binary file added
BIN
+26.6 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.typing.JuEstimatorLike.doctree
Binary file not shown.
Binary file added
BIN
+8.72 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.utils.warn_with_log.doctree
Binary file not shown.
Binary file added
BIN
+17.6 KB
pr-preview/pr-276/.doctrees/api/generated/julearn.viz.plot_scores.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+35.9 KB
pr-preview/pr-276/.doctrees/auto_examples/00_starting/plot_cm_acc_multiclass.doctree
Binary file not shown.
Binary file added
BIN
+39.6 KB
pr-preview/pr-276/.doctrees/auto_examples/00_starting/plot_example_regression.doctree
Binary file not shown.
Binary file added
BIN
+55.1 KB
pr-preview/pr-276/.doctrees/auto_examples/00_starting/plot_stratified_kfold_reg.doctree
Binary file not shown.
Binary file added
BIN
+71.2 KB
pr-preview/pr-276/.doctrees/auto_examples/00_starting/run_combine_pandas.doctree
Binary file not shown.
Binary file added
BIN
+53 KB
pr-preview/pr-276/.doctrees/auto_examples/00_starting/run_grouped_cv.doctree
Binary file not shown.
Binary file added
BIN
+50.9 KB
...eview/pr-276/.doctrees/auto_examples/00_starting/run_simple_binary_classification.doctree
Binary file not shown.
Binary file added
BIN
+11.4 KB
pr-preview/pr-276/.doctrees/auto_examples/00_starting/sg_execution_times.doctree
Binary file not shown.
Binary file added
BIN
+5.72 KB
pr-preview/pr-276/.doctrees/auto_examples/01_model_comparison/index.doctree
Binary file not shown.
Binary file added
BIN
+59.6 KB
...w/pr-276/.doctrees/auto_examples/01_model_comparison/plot_simple_model_comparison.doctree
Binary file not shown.
Binary file added
BIN
+5.4 KB
pr-preview/pr-276/.doctrees/auto_examples/01_model_comparison/sg_execution_times.doctree
Binary file not shown.
Binary file added
BIN
+10.6 KB
pr-preview/pr-276/.doctrees/auto_examples/02_inspection/index.doctree
Binary file not shown.
Binary file added
BIN
+58.8 KB
pr-preview/pr-276/.doctrees/auto_examples/02_inspection/plot_groupcv_inspect_svm.doctree
Binary file not shown.
Binary file added
BIN
+47.2 KB
pr-preview/pr-276/.doctrees/auto_examples/02_inspection/plot_inspect_random_forest.doctree
Binary file not shown.
Binary file added
BIN
+35.7 KB
pr-preview/pr-276/.doctrees/auto_examples/02_inspection/plot_preprocess.doctree
Binary file not shown.
Binary file added
BIN
+38.3 KB
pr-preview/pr-276/.doctrees/auto_examples/02_inspection/run_binary_inspect_folds.doctree
Binary file not shown.
Binary file added
BIN
+8.98 KB
pr-preview/pr-276/.doctrees/auto_examples/02_inspection/sg_execution_times.doctree
Binary file not shown.
Binary file added
BIN
+14.2 KB
pr-preview/pr-276/.doctrees/auto_examples/03_complex_models/index.doctree
Binary file not shown.
Binary file added
BIN
+26.8 KB
pr-preview/pr-276/.doctrees/auto_examples/03_complex_models/run_apply_to_target.doctree
Binary file not shown.
Binary file added
BIN
+44.7 KB
pr-preview/pr-276/.doctrees/auto_examples/03_complex_models/run_example_pca_featsets.doctree
Binary file not shown.
Binary file added
BIN
+54.6 KB
...r-276/.doctrees/auto_examples/03_complex_models/run_hyperparameter_multiple_grids.doctree
Binary file not shown.
Binary file added
BIN
+71.8 KB
...review/pr-276/.doctrees/auto_examples/03_complex_models/run_hyperparameter_tuning.doctree
Binary file not shown.
Binary file added
BIN
+51.9 KB
...6/.doctrees/auto_examples/03_complex_models/run_hyperparameter_tuning_bayessearch.doctree
Binary file not shown.
Binary file added
BIN
+36.1 KB
pr-preview/pr-276/.doctrees/auto_examples/03_complex_models/run_stacked_models.doctree
Binary file not shown.
Binary file added
BIN
+11.7 KB
pr-preview/pr-276/.doctrees/auto_examples/03_complex_models/sg_execution_times.doctree
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+51.9 KB
.../pr-276/.doctrees/auto_examples/04_confounds/plot_confound_removal_classification.doctree
Binary file not shown.
Binary file added
BIN
+94 KB
pr-preview/pr-276/.doctrees/auto_examples/04_confounds/run_return_confounds.doctree
Binary file not shown.
Binary file added
BIN
+6.58 KB
pr-preview/pr-276/.doctrees/auto_examples/04_confounds/sg_execution_times.doctree
Binary file not shown.
Binary file added
BIN
+5.92 KB
pr-preview/pr-276/.doctrees/auto_examples/05_customization/index.doctree
Binary file not shown.
Binary file added
BIN
+44.4 KB
...iew/pr-276/.doctrees/auto_examples/05_customization/run_custom_scorers_regression.doctree
Binary file not shown.
Binary file added
BIN
+5.36 KB
pr-preview/pr-276/.doctrees/auto_examples/05_customization/sg_execution_times.doctree
Binary file not shown.
Binary file not shown.
154 changes: 154 additions & 0 deletions
154
...f004c0db5a67b9da92838dd-auto_examples-01_model_comparison-plot_simple_model_comparison.js
Large diffs are not rendered by default.
Oops, something went wrong.
154 changes: 154 additions & 0 deletions
154
.../bokeh-content-c3c7dc374b1c444286b2adc90284fbfe-what_really_need_know-model_comparison.js
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+78.3 KB
pr-preview/pr-276/.doctrees/selected_deeper_topics/confound_removal.doctree
Binary file not shown.
Binary file added
BIN
+93 KB
pr-preview/pr-276/.doctrees/selected_deeper_topics/cross_validation_splitter.doctree
Binary file not shown.
Binary file added
BIN
+235 KB
pr-preview/pr-276/.doctrees/selected_deeper_topics/hyperparameter_tuning.doctree
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+73.1 KB
pr-preview/pr-276/.doctrees/selected_deeper_topics/model_inspect.doctree
Binary file not shown.
Binary file added
BIN
+66.8 KB
pr-preview/pr-276/.doctrees/selected_deeper_topics/stacked_models.doctree
Binary file not shown.
Binary file added
BIN
+35.3 KB
pr-preview/pr-276/.doctrees/selected_deeper_topics/target_transformers.doctree
Binary file not shown.
Binary file added
BIN
+21.4 KB
pr-preview/pr-276/.doctrees/what_really_need_know/cross_validation.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+63.8 KB
pr-preview/pr-276/.doctrees/what_really_need_know/model_comparison.doctree
Binary file not shown.
Binary file added
BIN
+116 KB
pr-preview/pr-276/.doctrees/what_really_need_know/model_evaluation.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
133 changes: 133 additions & 0 deletions
133
pr-preview/pr-276/_downloads/0fdc9a0d75a37f1ac1637ca54129dba7/plot_preprocess.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
""" | ||
Preprocessing with variance threshold, zscore and PCA | ||
===================================================== | ||
This example uses the ``make_regression`` function to create a simple dataset, | ||
performs a simple regression after the preprocessing of the features | ||
including removal of low variance features, feature normalization for only | ||
two features using zscore and feature reduction using PCA. | ||
We will check the features after each preprocessing step. | ||
""" | ||
# Authors: Shammi More <[email protected]> | ||
# Leonard Sasse <[email protected]> | ||
# License: AGPL | ||
|
||
import matplotlib.pyplot as plt | ||
import pandas as pd | ||
import seaborn as sns | ||
from sklearn.datasets import make_regression | ||
|
||
from julearn import run_cross_validation | ||
from julearn.inspect import preprocess | ||
from julearn.pipeline import PipelineCreator | ||
from julearn.utils import configure_logging | ||
|
||
############################################################################### | ||
# Set the logging level to info to see extra information. | ||
configure_logging(level="INFO") | ||
|
||
############################################################################### | ||
# Create a dataset using ``sklearn`` ``make_regression``. | ||
df = pd.DataFrame() | ||
X, y = [f"Feature {x}" for x in range(1, 5)], "y" | ||
df[X], df[y] = make_regression( | ||
n_samples=100, n_features=4, n_informative=3, noise=0.3, random_state=0 | ||
) | ||
|
||
# We only want to zscore the first two features, so let's get their names. | ||
first_two = X[:2] | ||
|
||
# We can define a dictionary, in which the 'key' defines the names of our | ||
# different 'types' of 'X'. The 'value' determine, which features belong to | ||
# this type. | ||
X_types = {"X_to_zscore": first_two} | ||
|
||
############################################################################### | ||
# Let's look at the summary statistics of the raw features. | ||
print("Summary Statistics of the raw features : \n", df.describe()) | ||
|
||
############################################################################### | ||
# We will preprocess all features using variance thresholding. | ||
# We will only zscore the first two features, and then perform PCA using all | ||
# features. We will zscore the target and then train a random forest model. | ||
# Since we use the PipelineCreator object we have to explicitly declare which | ||
# `X_types` each preprocessing step should be applied to. If we do not declare | ||
# the type in the ``add`` method using the ``apply_to`` keyword argument, | ||
# the step will default to ``"continuous"`` or to another type that can be | ||
# declared in the constructor of the ``PipelineCreator``. | ||
# To transform the target we could set ``apply_to="target"``, which is a special | ||
# type, that cannot be user-defined. Please note also that if a step is added | ||
# to transform the target, you also have to explicitly add the model that is | ||
# to be used in the regression to the ``PipelineCreator``. | ||
|
||
# Define model parameters and preprocessing steps first | ||
# The hyperparameters for each step can be added as a keyword argument and | ||
# should be either one parameter or an iterable of multiple parameters for a | ||
# search. | ||
|
||
# Setting the threshold for variance to 0.15, number of PCA components to 2 | ||
# and number of trees for random forest to 200. | ||
|
||
# By setting "apply_to=*", we can apply the preprocessing step to all features. | ||
pipeline_creator = PipelineCreator(problem_type="regression") | ||
|
||
pipeline_creator.add("select_variance", apply_to="*", threshold=0.15) | ||
pipeline_creator.add("zscore", apply_to="X_to_zscore") | ||
pipeline_creator.add("pca", apply_to="*", n_components=2) | ||
pipeline_creator.add("rf", apply_to="*", n_estimators=200) | ||
|
||
# Because we have already added the model to the pipeline creator, we can | ||
# simply drop in the ``pipeline_creator`` as a model. If we did not add a model | ||
# here, we could add the ``pipeline_creator`` using the keyword argument | ||
# ``preprocess`` and hand over a model separately. | ||
|
||
scores, model = run_cross_validation( | ||
X=X, | ||
y=y, | ||
X_types=X_types, | ||
data=df, | ||
model=pipeline_creator, | ||
scoring=["r2", "neg_mean_absolute_error"], | ||
return_estimator="final", | ||
seed=200, | ||
) | ||
|
||
# We can use the final estimator to inspect the transformed features at a | ||
# specific step of the pipeline. Since the PCA was the last step added to the | ||
# pipeline, we can simply get the model up to this step by indexing as follows: | ||
|
||
X_after_pca = model[:-1].transform(df[X]) | ||
|
||
print("X after PCA:") | ||
print("=" * 79) | ||
print(X_after_pca) | ||
|
||
# We can select pipelines up to earlier steps by indexing previous elements | ||
# in the final estimator. For example, to inspect features after the zscoring | ||
# step: | ||
|
||
X_after_zscore = model[:-2].transform(df[X]) | ||
print("X after zscore:") | ||
print("=" * 79) | ||
print(X_after_zscore) | ||
|
||
# However, to make this less confusing you can also simply use the high-level | ||
# function ``preprocess`` to explicitly refer to a pipeline step by name: | ||
|
||
X_after_pca = preprocess(model, X=X, data=df, until="pca") | ||
X_after_zscore = preprocess(model, X=X, data=df, until="zscore") | ||
|
||
# Let's plot scatter plots for raw features and the PCA components. | ||
fig, axes = plt.subplots(1, 2, figsize=(12, 6)) | ||
sns.scatterplot(x=X[0], y=X[1], data=df, ax=axes[0]) | ||
axes[0].set_title("Raw features") | ||
sns.scatterplot(x="pca0", y="pca1", data=X_after_pca, ax=axes[1]) | ||
axes[1].set_title("PCA components") | ||
|
||
############################################################################### | ||
# Let's look at the summary statistics of the zscored features. We see here | ||
# that the mean of all the features is zero and standard deviation is one. | ||
print( | ||
"Summary Statistics of the zscored features : \n", | ||
X_after_zscore.describe(), | ||
) |
169 changes: 169 additions & 0 deletions
169
...r-276/_downloads/2c2781f9a637943101f9b9d122327ef8/run_hyperparameter_multiple_grids.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n# Tuning Multiple Hyperparameters Grids\n\nThis example uses the ``fmri`` dataset, performs simple binary classification\nusing a Support Vector Machine classifier while tuning multiple hyperparameters\ngrids at the same time.\n\n## References\n\n Waskom, M.L., Frank, M.C., Wagner, A.D. (2016). Adaptive engagement of\n cognitive control in context-dependent decision-making. Cerebral Cortex.\n\n.. include:: ../../links.inc\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Authors: Federico Raimondo <[email protected]>\n# License: AGPL\n\nimport numpy as np\nfrom seaborn import load_dataset\n\nfrom julearn import run_cross_validation\nfrom julearn.utils import configure_logging\nfrom julearn.pipeline import PipelineCreator" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Set the logging level to info to see extra information.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"configure_logging(level=\"INFO\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Set the random seed to always have the same example.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"np.random.seed(42)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Load the dataset.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"df_fmri = load_dataset(\"fmri\")\ndf_fmri.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Set the dataframe in the right format.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"df_fmri = df_fmri.pivot(\n index=[\"subject\", \"timepoint\", \"event\"], columns=\"region\", values=\"signal\"\n)\n\ndf_fmri = df_fmri.reset_index()\ndf_fmri.head()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Lets do a first attempt and use a linear SVM with the default parameters.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"X = [\"frontal\", \"parietal\"]\ny = \"event\"\n\ncreator = PipelineCreator(problem_type=\"classification\")\ncreator.add(\"zscore\")\ncreator.add(\"svm\", kernel=\"linear\")\n\nscores = run_cross_validation(X=X, y=y, data=df_fmri, model=creator)\n\nprint(scores[\"test_score\"].mean())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Now let's tune a bit this SVM. We will use a grid search to tune the\nregularization parameter ``C`` and the kernel. We will also tune the ``gamma``.\nBut since the ``gamma`` is only used for the rbf kernel, we will use a\ndifferent grid for the ``\"rbf\"`` kernel.\n\nTo specify two different sets of parameters for the same step, we can\nexplicitly specify the name of the step. This is done by passing the\n``name`` parameter to the ``add`` method.\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"creator = PipelineCreator(problem_type=\"classification\")\ncreator.add(\"zscore\")\ncreator.add(\"svm\", kernel=\"linear\", C=[0.01, 0.1], name=\"svm\")\ncreator.add(\n \"svm\",\n kernel=\"rbf\",\n C=[0.01, 0.1],\n gamma=[\"scale\", \"auto\", 1e-2, 1e-3],\n name=\"svm\",\n)\n\nsearch_params = {\n \"kind\": \"grid\",\n \"cv\": 2, # to speed up the example\n}\n\nscores, estimator = run_cross_validation(\n X=X,\n y=y,\n data=df_fmri,\n model=creator,\n search_params=search_params,\n return_estimator=\"final\",\n)\n\nprint(scores[\"test_score\"].mean())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"It seems that we might have found a better model, but which one is it?\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(estimator.best_params_)\nprint(estimator.best_estimator_[\"svm\"]._gamma)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.15" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Oops, something went wrong.