ETA444 / datasafari

DataSafari simplifies complex data science tasks into straightforward, powerful one-liners.
https://datasafari.dev
GNU General Public License v3.0
2 stars 0 forks source link

Implement error handling for model_tuning_core() #112

Closed ETA444 closed 4 months ago

ETA444 commented 4 months ago

Error Handling in model_tuning_core()

Type Validations

if not isinstance(x_train, (pd.DataFrame, np.ndarray)):
    raise TypeError("model_tuning_core(): 'x_train' must be a pandas DataFrame or NumPy ndarray.")
if not isinstance(y_train, (pd.Series, np.ndarray)):
    raise TypeError("model_tuning_core(): 'y_train' must be a pandas Series or NumPy ndarray.")
if not isinstance(task_type, str):
    raise TypeError("model_tuning_core(): 'task_type' must be a string.")
if not isinstance(models, dict):
    raise TypeError("model_tuning_core(): 'models' must be a dictionary with model names as keys and model instances as values.")
if priority_metrics is not None and not isinstance(priority_metrics, list):
    raise TypeError("model_tuning_core(): 'priority_metrics' must be a list of strings.")
if refit_metric is not None and not isinstance(refit_metric, (str, Callable)):
    raise TypeError("model_tuning_core(): 'refit_metric' must be either a string or a callable object.")

Value Validations

if task_type not in ['classification', 'regression']:
    raise ValueError("model_tuning_core(): 'task_type' must be either 'classification' or 'regression'.")
if n_top_models <= 0:
    raise ValueError("model_tuning_core(): 'n_top_models' must be an integer greater than 0.")
if x_train.shape[0] != y_train.shape[0]:
    raise ValueError("model_tuning_core(): 'x_train' and 'y_train' must have the same number of rows.")
if x_train.size == 0 or y_train.size == 0:
    raise ValueError("model_tuning_core(): 'x_train' and 'y_train' cannot be empty.")
if any(not isinstance(metric, str) for metric in priority_metrics):
    raise ValueError("model_tuning_core(): All elements in 'priority_metrics' must be strings.")
if priority_tuners and any(tuner not in ['grid', 'random', 'bayesian'] for tuner in priority_tuners):
    raise ValueError("model_tuning_core(): 'priority_tuners' contains unrecognized tuners. Valid tuners are 'grid', 'random', 'bayesian'.")
if cv < 1:
    raise ValueError("model_tuning_core(): 'cv' must be an integer greater than 0.")
if n_iter_random is not None and n_iter_random < 1:
    raise ValueError("model_tuning_core(): 'n_iter_random' must be a non-negative integer greater than 0.")
if n_iter_bayesian is not None and n_iter_bayesian < 1:
    raise ValueError("model_tuning_core(): 'n_iter_bayesian' must be a non-negative integer greater than 0.")