Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX formatting in docs #342

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix formatting in docs
  • Loading branch information
ravinkohli committed Nov 22, 2021
commit 86c3245893be61992adef1b9bbf8c6cc1d07d803
153 changes: 76 additions & 77 deletions examples/40_advanced/example_custom_configuration_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

The following example shows how adjust the configuration space of
the search. Currently, there are two changes that can be made to the space:-

1. Adjust individual hyperparameters in the pipeline
2. Include or exclude components:
a) include: Dictionary containing components to include. Key is the node
Expand Down Expand Up @@ -57,80 +58,78 @@ def get_search_space_updates():
return updates


if __name__ == '__main__':

############################################################################
# Data Loading
# ============
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
X,
y,
random_state=1,
)

############################################################################
# Build and fit a classifier with include components
# ==================================================
api = TabularClassificationTask(
search_space_updates=get_search_space_updates(),
include_components={'network_backbone': ['MLPBackbone', 'ResNetBackbone'],
'encoder': ['OneHotEncoder']}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train.copy(),
y_train=y_train.copy(),
X_test=X_test.copy(),
y_test=y_test.copy(),
optimize_metric='accuracy',
total_walltime_limit=150,
func_eval_time_limit_secs=30
)

############################################################################
# Print the final ensemble performance
# ====================================
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
print(api.show_models())

# Print statistics from search
print(api.sprint_statistics())

############################################################################
# Build and fit a classifier with exclude components
# ==================================================
api = TabularClassificationTask(
search_space_updates=get_search_space_updates(),
exclude_components={'network_backbone': ['MLPBackbone'],
'encoder': ['OneHotEncoder']}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train,
y_train=y_train,
X_test=X_test.copy(),
y_test=y_test.copy(),
optimize_metric='accuracy',
total_walltime_limit=150,
func_eval_time_limit_secs=30
)

############################################################################
# Print the final ensemble performance
# ====================================
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
print(api.show_models())

# Print statistics from search
print(api.sprint_statistics())
############################################################################
# Data Loading
# ============
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
X,
y,
random_state=1,
)

############################################################################
# Build and fit a classifier with include components
# ==================================================
api = TabularClassificationTask(
search_space_updates=get_search_space_updates(),
include_components={'network_backbone': ['MLPBackbone', 'ResNetBackbone'],
'encoder': ['OneHotEncoder']}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train.copy(),
y_train=y_train.copy(),
X_test=X_test.copy(),
y_test=y_test.copy(),
Comment on lines +84 to +87
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.copy()

optimize_metric='accuracy',
total_walltime_limit=150,
func_eval_time_limit_secs=30
)

############################################################################
# Print the final ensemble performance
# ====================================
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
print(api.show_models())

# Print statistics from search
print(api.sprint_statistics())

############################################################################
# Build and fit a classifier with exclude components
# ==================================================
api = TabularClassificationTask(
search_space_updates=get_search_space_updates(),
exclude_components={'network_backbone': ['MLPBackbone'],
'encoder': ['OneHotEncoder']}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train,
y_train=y_train,
X_test=X_test.copy(),
y_test=y_test.copy(),
Comment on lines +119 to +120
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.copy()

optimize_metric='accuracy',
total_walltime_limit=150,
func_eval_time_limit_secs=30
)

############################################################################
# Print the final ensemble performance
# ====================================
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
print(api.show_models())

# Print statistics from search
print(api.sprint_statistics())
11 changes: 6 additions & 5 deletions examples/40_advanced/example_parallel_n_jobs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
======================
Tabular Classification
======================
============================================
Tabular Classification with n parallel jobs
============================================

The following example shows how to fit a sample classification model parallely on 2 cores
with AutoPyTorch

"""
import os
import tempfile as tmp
Expand Down Expand Up @@ -60,9 +61,9 @@
############################################################################
# Print the final ensemble performance
# ====================================
print(api.run_history, api.trajectory)
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
# Print the final ensemble built by AutoPyTorch
print(api.show_models())
print(api.sprint_statistics())

29 changes: 20 additions & 9 deletions examples/40_advanced/example_resampling_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
from autoPyTorch.api.tabular_classification import TabularClassificationTask
from autoPyTorch.datasets.resampling_strategy import CrossValTypes, HoldoutValTypes

############################################################################
# Default Resampling Strategy
# ============================

############################################################################
# Data Loading
# ============
# ------------
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
X,
Expand All @@ -39,7 +42,7 @@

############################################################################
# Build and fit a classifier with default resampling strategy
# ===========================================================
# -----------------------------------------------------------
api = TabularClassificationTask(
# 'HoldoutValTypes.holdout_validation' with 'val_share': 0.33
# is the default argument setting for TabularClassificationTask.
Expand All @@ -51,7 +54,7 @@

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
# -----------------------------------------------------
api.search(
X_train=X_train,
y_train=y_train,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.copy()

Expand All @@ -64,7 +67,7 @@

############################################################################
# Print the final ensemble performance
# ====================================
# ------------------------------------
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
Expand All @@ -76,17 +79,21 @@

############################################################################

############################################################################
# Cross validation Resampling Strategy
# =====================================

############################################################################
# Build and fit a classifier with Cross validation resampling strategy
# ====================================================================
# --------------------------------------------------------------------
api = TabularClassificationTask(
resampling_strategy=CrossValTypes.k_fold_cross_validation,
resampling_strategy_args={'num_splits': 3}
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
# ------------
ravinkohli marked this conversation as resolved.
Show resolved Hide resolved
api.search(
X_train=X_train,
y_train=y_train,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.copy()

Expand All @@ -99,7 +106,7 @@

############################################################################
# Print the final ensemble performance
# ====================================
# ------------
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
Expand All @@ -111,9 +118,13 @@

############################################################################

############################################################################
# Stratified Resampling Strategy
# ===============================

############################################################################
# Build and fit a classifier with Stratified resampling strategy
# ==============================================================
# --------------------------------------------------------------
api = TabularClassificationTask(
# For demonstration purposes, we use
# Stratified hold out validation. However,
Expand All @@ -124,7 +135,7 @@

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
# -----------------------------------------------------
api.search(
X_train=X_train,
y_train=y_train,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.copy()

Expand Down
84 changes: 41 additions & 43 deletions examples/40_advanced/example_run_with_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,48 @@
from autoPyTorch.api.tabular_classification import TabularClassificationTask


if __name__ == '__main__':
############################################################################
# Data Loading
# ============
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
X,
y,
random_state=42,
)

############################################################################
# Data Loading
# ============
X, y = sklearn.datasets.fetch_openml(data_id=40981, return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(
X,
y,
random_state=42,
)
############################################################################
# Build and fit a classifier
# ==========================
api = TabularClassificationTask(
seed=42,
)

############################################################################
# Build and fit a classifier
# ==========================
api = TabularClassificationTask(
seed=42,
)
############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train,
y_train=y_train,
X_test=X_test.copy(),
y_test=y_test.copy(),
Comment on lines +50 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.copy()

optimize_metric='accuracy',
total_walltime_limit=300,
func_eval_time_limit_secs=50,
# Setting this option to "greedy"
# will make smac run the configurations
# present in 'autoPyTorch/configs/greedy_portfolio.json'
portfolio_selection="greedy"
)

############################################################################
# Search for an ensemble of machine learning algorithms
# =====================================================
api.search(
X_train=X_train,
y_train=y_train,
X_test=X_test.copy(),
y_test=y_test.copy(),
optimize_metric='accuracy',
total_walltime_limit=300,
func_eval_time_limit_secs=50,
# Setting this option to "greedy"
# will make smac run the configurations
# present in 'autoPyTorch/configs/greedy_portfolio.json'
portfolio_selection="greedy"
)
############################################################################
# Print the final ensemble performance
# ====================================
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
# Print the final ensemble built by AutoPyTorch
print(api.show_models())

############################################################################
# Print the final ensemble performance
# ====================================
y_pred = api.predict(X_test)
score = api.score(y_pred, y_test)
print(score)
# Print the final ensemble built by AutoPyTorch
print(api.show_models())

# Print statistics from search
print(api.sprint_statistics())
# Print statistics from search
print(api.sprint_statistics())