ilovebandits.data_bandits package
Submodules
ilovebandits.data_bandits.base module
DATABASED BANDITS. Transform classification datasets into bandit problems.
- class ilovebandits.data_bandits.base.DataBasedBanditFromPandas(df: DataFrame, reward_delay: int = 0, random_state=None)
Bases:
objectInitialize the DataBasedbandit with a DataFrame.
Transforms a classification problem into a bandit problem. It assumes the last column of the DataFrame is the target variable. Each class is considered an arm. If the action taken mathches the target label, it gives a reward of 1, 0 otherwise.
Parameters
- df: pd.DataFrame
DataFrame containing the data for the bandit. The last column should be the target variable
- reward_delay: int, optional
Delay in the reward. Default is 0, meaning no delay. This can be useful for simulating environments where the reward is not immediate.
- get_current_context()
Get the current context.
- Returns:
Current context as a numpy array with shape (1, nfeats).
- reset_env()
Reset DataBasedBandit.
ilovebandits.data_bandits.utils module
Utils for downloading and processing data for bandit simulations. Based on genrl library’s data_bandits.
- class ilovebandits.data_bandits.utils.GenrlBanditDataLoader(force_download: bool = False)
Bases:
objectClass to load datasets in genrl library such as the Statlog Shuttle data.
- get_data(path: str, url: str) DataFrame
Download and decompress the shuttle data as a pandas DataFrame.
- get_statlog_shuttle_data() DataFrame
Get the Statlog Shuttle data as a pandas DataFrame.
- ilovebandits.data_bandits.utils.download_data(path: str, url: str, force: bool = False, filename: str | None = None) str
Download data to given location from given URL. TAken from: https://github.com/SforAiDl/genrl/blob/ce767e43859a65e67d3ec1f7ca59b751b114615f/genrl/utils/data_bandits/utils.py .
Args: path (str): Location to download to. url (str): URL to download file from. force (bool, optional): Force download even if file exists. Defaults to False. filename (Union[str, None], optional): Name to save file under. Defaults to None which implies original filename is to be used.
Returns
str: Path to downloaded file.
- ilovebandits.data_bandits.utils.fetch_data_without_header(path: str | Path, fname: str, delimiter: str = ',', na_values: list = [])
Auxiliary function taken from https://github.com/SforAiDl/genrl/blob/ce767e43859a65e67d3ec1f7ca59b751b114615f/genrl/utils/data_bandits/utils.py .
- ilovebandits.data_bandits.utils.try_data_download(fpath: Path, path: Path, url: str)
Auxiliary function taken from https://github.com/SforAiDl/genrl/blob/ce767e43859a65e67d3ec1f7ca59b751b114615f/genrl/utils/data_bandits/utils.py .