GCL.eval¶
Available Evaluation Models¶
Base class for trainable (e.g., logistic regression) evaluation. |
|
Base class for sklearn-based evaluation. |
|
Evaluate using a trainable logistic regression model. |
|
Evaluate using the sklearn logistic regression classifier. |
|
Evaluate using the sklearn SVM classifier. |
|
Evaluate using the sklearn random forest classifier. |
|
Generate split indices for training, test, and validation sets. |
|
Convert from PyG split indices of training, test, and validation sets. |
Evaluation Models¶
- class BaseSKLearnEvaluator(evaluator, metrics, split, params=None, param_grid=None, grid_search_scoring=None, grid_search_params=None)¶
Base class for sklearn-based evaluation.
- Parameters
evaluator (BaseEstimator) – The sklearn evaluator.
metrics (Dict[str, Callable]) – The metrics to evaluate in a dictionary with metric names as keys and callables as values.
split (Union[List[Dict], BaseCrossValidator]) – A list of split indices (for multiple folds), or a sklearn cross-validator. If a list of indices is given, the validation set will be ignored.
params (Dict, optional) – Other parameters for the evaluator. (default:
None)param_grid (List[Dict], optional) – The parameter grid for the grid search. (default:
None)grid_search_scoring (Dict[str, Callable], optional) – If
param_gridis given, provide metrics in grid search. If multiple metrics are given, the first one will be used to retrain the best model. (default:None)grid_search_params (Dict, optional) – If
param_gridis given, further pass the parameters for the sklearn grid search cross-validator. See sklearn GridSearchCV for details. (default:None)
- class BaseTrainableEvaluator(model, optimizer, optimizer_params, objective, split, metrics, device='cpu', num_epochs=1000, test_interval=20, test_metric=None)¶
Base class for trainable (e.g., logistic regression) evaluation.
- Parameters
model (torch.nn.Module) – The evaluation model to train. It should implement a
predictfunction to convert logits to predictions.optimizer (Optimizer) – The optimizer class for training.
optimizer_params (Dict) – The parameters for the optimizer.
objective (Callable) – The objective function to use for training. Its signature should be like
f(logits, y).split (Union[List[Dict], BaseCrossValidator]) – A list of split indices (for multiple folds), or a sklearn cross-validator.
metrics (Dict[str, Callable]) – The metrics to evaluate in a dictionary with metric names as keys and callables as values.
device (Union[str, torch.device]) – The device to use for training. (default:
'cpu')num_epochs (int) – The number of epochs to train the model. (default:
1000)test_interval (int) – The number of epochs between each test. (default:
20)test_metric (Union[Callable, str], optional) – The metric to test on the validation set during training. It could be a callable function, or a string specifying the key in
metrics. If set toNone, the test metric will be the first inmetrics. Ifsplitis a sklearn cross-validator, this parameter is ignored as no validation set is used. (default:None)
- class LRSklearnEvaluator(metrics, split, params=None, param_grid=None, grid_search_scoring=None, grid_search_params=None)¶
Evaluate using the sklearn logistic regression classifier.
- Parameters
metrics (Dict[str, Callable]) – The metrics to evaluate in a dictionary with metric names as keys and callables as values.
split (BaseCrossValidator) – The sklearn cross-validator to split the data.
params (Dict, optional) – Other parameters for the logistic regression model. See sklearn LogisticRegression for details. (default:
None)param_grid (List[Dict], optional) – The parameter grid for the grid search. (default:
None)grid_search_scoring (Dict[str, Callable], optional) – If
param_gridis given, provide metrics in grid search. If multiple metrics are given, the first one will be used to retrain the best model. (default:None)grid_search_params (Dict, optional) –
If
param_gridis given, further pass the parameters for the sklearn grid search cross-validator. See sklearn GridSearchCV for details. (default:None)
- class LRTrainableEvaluator(input_dim, num_classes, split, metrics, device='cpu', num_epochs=5000, learning_rate=0.01, weight_decay=0.0, test_interval=20, test_metric=None)¶
Evaluate using a trainable logistic regression model.
- Parameters
input_dim (int) – The dimension of the input data.
num_classes (int) – The number of classes.
split (Union[List[Dict], BaseCrossValidator]) – A list of split indices (for multiple folds), or a sklearn cross-validator.
metrics (Dict[str, Callable]) – The metrics to evaluate in a dictionary with metric names as keys and callables as values.
device (Union[str, torch.device]) – The device to use for training. (default:
'cpu')num_epochs (int) – The number of epochs to train. (default:
5000)learning_rate (float) – The learning rate for the optimizer. (default:
0.01)weight_decay (float) – The weight decay for the optimizer. (default:
0.0)test_interval (int) – The number of epochs between each test. (default:
20)test_metric (Union[Callable, str], optional) – The metric to test on the validation set during training. It could be a callable function, or a string specifying the key in
metrics. If set toNone, the test metric will be the first inmetrics. Ifsplitis a sklearn cross-validator, this parameter is ignored as no validation set is used. (default:None)
- class RFEvaluator(metrics, split, params=None, param_grid=None, grid_search_scoring=None, grid_search_params=None)¶
Evaluate using the sklearn random forest classifier.
- Parameters
metrics (Dict[str, Callable]) – The metrics to evaluate in a dictionary with metric names as keys and callables as values.
split (BaseCrossValidator) – The sklearn cross-validator to split the data.
params (Dict, optional) – Other parameters for the random forest classifier. See sklearn RandomForestClassifier for details. (default:
None)param_grid (List[Dict], optional) – The parameter grid for the grid search. (default:
None)grid_search_scoring (Dict[str, Callable], optional) – If
param_gridis given, provide metrics in grid search. If multiple metrics are given, the first one will be used to retrain the best model. (default:None)grid_search_params (Dict, optional) –
If
param_gridis given, further pass the parameters for the sklearn grid search cross-validator. See sklearn GridSearchCV for details. (default:None)
- class SVMEvaluator(metrics, split, linear=True, params=None, param_grid=None, grid_search_scoring=None, grid_search_params=None)¶
Evaluate using the sklearn SVM classifier.
- Parameters
metrics (Dict[str, Callable]) – The metrics to evaluate in a dictionary with metric names as keys and callables as values.
split (BaseCrossValidator) – The sklearn cross-validator to split the data.
params (Dict, optional) – Other parameters for the SVM model. See sklearn SVC for details. (default:
None)param_grid (List[Dict], optional) – The parameter grid for the grid search. (default:
None)grid_search_scoring (Dict[str, Callable], optional) – If
param_gridis given, provide metrics in grid search. If multiple metrics are given, the first one will be used to retrain the best model. (default:None)grid_search_params (Dict, optional) –
If
param_gridis given, further pass the parameters for the sklearn grid search cross-validator. See sklearn GridSearchCV for details. (default:None)
- from_PyG_split(data)¶
Convert from PyG split indices of training, test, and validation sets.
- Parameters
data (Data) – A PyG data object.
- Returns
A list of dictionaries of split indices.
- Return type
List[Dict]
- Raises
ValueError – If the
dataobject does not have the split indices.
- random_split(num_samples, num_splits=1, train_ratio=0.1, test_ratio=0.8)¶
Generate split indices for training, test, and validation sets.
- Parameters
- Returns
A list of dictionaries of split indices.
- Return type
List[Dict]
Examples
>>> random_split(10, num_splits=1, train_ratio=0.5, test_ratio=0.4) [{'train': [3, 4, 0, 1, 2], 'test': [5, 7, 6, 8], 'valid': [9]}]