par_coordinates package
par_coordinates.get_results module
- par_coordinates.get_results.keras_tuner(tuner, metric, num_best_trials=1)[source]
Retrieves results dataframe for the hyperparameter search from a keras_tuner.tuners object. This library supports grid search, random search and Bayesian optimization. It is suited for TensorFlow and, through Keras 3.0, for PyTorch and JAX as well.
- Parameters:
tuner (keras_tuner.tuners) – tuner after hyperparameter search
metric (str) – name of the metric to retrieve (example: “val_accuracy”)
num_best_trials (int) – how many trials to retrieve, in order of best performance (default to 1)
- Returns:
results dataframe for the hyperparameter search
- Return type:
pd.DataFrame
- par_coordinates.get_results.optuna(study, metric, custom_columns=[])[source]
Retrieves results dataframe for the hyperparameter search from a optuna study object. This library offers advanced tools for Bayesian optimization and is compatible with all the major machine learning/deep learning frameworks.
- Parameters:
study (optuna.study) – optimized optuna study after hyperparameter search
metric (str) – name of the metric to retrieve (example: “mse”)
custom_columns (list) – list of names for custom columns defined by the user (default to [])
- Returns:
results dataframe for the hyperparameter search
- Return type:
pd.DataFrame
- par_coordinates.get_results.sklearn(tuner, metric)[source]
Retrieves results dataframe for the hyperparameter search from a GridSearchCV or RandomizedSearchCV object.
- Parameters:
tuner (sklearn.model_selection.GridSearchCV/RandomizedSearchCV) – fitted model after hyperparameter search
metric (str) – name of the metric to retrieve (example: “mean_test_score”)
- Returns:
results dataframe for the hyperparameter search
- Return type:
pd.DataFrame
par_coordinates.plot module
- par_coordinates.plot.get_path(data, i)[source]
Interpolates a curve between the various points for a given observation.
- Parameters:
data (np.ndarray) – processed and rescaled data array (returned by rescale_data)
i (int) – specifies which observation we are considering
- Returns:
interpolated curve
- Return type:
matplotlib.path.Path
- par_coordinates.plot.get_performance(data, ylim)[source]
Retrieves and scales the last column corresponding to performance metric.
- Parameters:
data (np.ndarray) – processed data array (returned by replace_str_values)
ylim (list) – list specifying y-axis limits for columns in data (returned by set_ylim)
- Returns:
performance metric scaled to [0, 1]
- Return type:
np.ndarray
- par_coordinates.plot.plot_par_coordinates(data, labels=None, ytype=None, ylim=None, ylabels=None, figsize=(10, 5), rect=[0.125, 0.1, 0.75, 0.8], curves=True, linewidth=1.0, alpha=1.0, colorbar=True, colorbar_width=0.02, cmap=<matplotlib.colors.ListedColormap object>)[source]
Displays a parallel coordinates plot of the hyperparameters search.
- Parameters:
data (pd.DataFrame) – pandas dataframe where the last column is the performance metric, the others represent
search (the various hyperparameters values for the) –
labels (list) – labels for y-axes (default to None)
ytype (list) – data type for each axis. Defaults to None which is then mapped to “factor” for strings and “linear” for floats. If ytype is passed, logarithmic axes are also possible, example: [“factor”, “linear”, “log”, [], …]. Empty fields must be filled with an empty list []
ylim (list) – limits for each axis (default to None). Custom min and max values can be passed, example: [[0, 1], [], …]
ylabels (list) – y-tick labels for each axis (default to None). Only use this option if you want to print more categories than you have in your dataset for factor axes. Requires ylim to be set correctly
figsize (tuple) – width, height in inches of the image (default to None)
rect – (list): [left, bottom, width, height], defines the position of the figure on the canvas (default to [0.125, 0.1, 0.75, 0.8])
curves (bool) – if True, B-spline curves are drawn instead of simple lines (default to True)
linewidth (float) – width of the curves/lines (default to 1.0)
alpha (float) – transparency of the curves/lines in [0, 1] scale (default to 1.0)
colorbar (bool) – if True, colorbar for the performance metric is drawn (default to True)
colorbar_width (float) – width of the colorbar (default to 0.02)
cmap (matplotlib.colors.Colormap) – color palette for colorbar (default to “inferno_r”)
- Returns:
figure to be displayed, saved or further customized
- Return type:
matplotlib.figure.Figure
- par_coordinates.plot.replace_str_values(data, ytype, ylabels)[source]
Casts dataframe to numpy for better handling of strings in matplotlib.
- Parameters:
data (pd.DataFrame) – results dataframe from hyperparameter tuning
ytype (list) – list specifying “factor”, “linear” or “log” for each column (returned by set_ytype)
ylabels (list) – list specifying the correct labels for each column (returned by set_ylabels)
- Returns:
processed data array
- Return type:
np.ndarray
- par_coordinates.plot.rescale_data(data, ytype, ylim)[source]
Scales secondary y-axes to scale of the main y-axis to guarantee alignment.
- Parameters:
data (np.ndarray) – processed data array (returned by replace_str_values)
ytype (list) – list specifying “factor”, “linear” or “log” for each column (returned by set_ytype)
ylim (list) – list specifying y-axis limits for columns in data (returned by set_ylim)
- Returns:
rescaled data array
- Return type:
np.ndarray
- par_coordinates.plot.set_ylabels(data, ytype, ylabels=None)[source]
Specifies for all columns the labels to use in the plot.
- Parameters:
data (pd.DataFrame) – results dataframe from hyperparameter tuning
ytype (list) – list specifying “factor”, “linear” or “log” for each column (returned by set_ytype)
ylabels (list) – list specifying the correct labels for each column (by default None)
- Returns:
list specifying the correct labels for each column
- Return type:
list
- par_coordinates.plot.set_ylim(data, ylim=None)[source]
Defines y-axis limits for columns in data.
- Parameters:
data (np.ndarray) – processed data array (returned by replace_str_values)
ylim (list) – list specifying y-axis limits for columns in data (by default None)
- Returns:
list specifying y-axis limits for columns in data
- Return type:
list
- par_coordinates.plot.set_ytype(data, ytype=None, colorbar=False)[source]
Specifies for each column if the data is factor, linear or logarithmic.
- Parameters:
data (pd.DataFrame) – results dataframe from hyperparameter tuning
ytype (list) – list specifying “factor”, “linear” or “log” for each column (by default None)
colorbar (bool) – True if colorbar needs to be displayed (by default False)
- Returns:
list specifying “factor”, “linear” or “log” for each column
- Return type:
list