ranker¶
- class fairdiverse.search.ranker_model.ranker.Ranker(configs, dataset)[source]¶
Bases:
ABC
Ranker class for training and evaluating ranking models.
This abstract class provides methods for training ranking models and evaluating their fairness using the provided dataset and configuration settings.
- :param configsdict
Configuration dictionary containing paths and settings for the model and evaluation.
- :param datasetobject
The dataset object containing data and metadata for training and evaluation.
- evaluate(file_name)[source]¶
Evaluate multiple runs of the ranking model using fairness metrics.
This method evaluates the model for all runs using the specified fairness metrics from the configuration.
- :param file_namestr
The name of the file to evaluate.
- :returnNone
This method does not return anything. It performs the evaluation and saves the results.
- evaluate_run(pred, run, file_name)[source]¶
Evaluate the results of a specific run and compute fairness metrics.
This method evaluates the predictions using fairness metrics for each sensitive attribute in the dataset and saves the evaluation results.
- :param predpandas.DataFrame
The predictions to be evaluated.
- :param runstr
The identifier for the specific run.
- :param file_namestr
The name of the file containing predictions to evaluate.
- :returnNone
This method does not return anything. It saves the evaluation results to the file.
- abstract predict(data, run, file_name)[source]¶
Predict ranking scores for the given data.
This method is abstract and should be implemented in subclasses to predict ranking scores based on the trained model. It appends the predicted scores to the provided data.
- :param datapandas.DataFrame
The data to be used for prediction.
- :param runstr
The identifier for the specific run.
- :param file_namestr
The name of the file where predictions will be saved.
- :returnpandas.DataFrame
The data with an added column containing predicted ranking scores.
- abstract train(data_train, data_test)[source]¶
Train the ranking model.
This method is abstract and needs to be implemented in the subclasses to train a ranking model based on the provided training and testing data. The trained model is saved at a specific location.
- :param data_trainpandas.DataFrame
The data to be used for training the ranking model.
- :param data_testpandas.DataFrame
The data to be used for testing the ranking model.
- :returnNone
This method does not return anything. It saves the trained model to a file.