Skip to main content

No project description provided

Project description

gobrec

GOBRec: GPU Optimized Bandits Recommender

Usage

Using a MAB Algorithm individually to generate arm scores

import numpy as np
# Import LinUCB as an example, it could be also LinTS or LinGreedy
from gobrec.mabs.lin_mabs import LinUCB

# A batch of contexts for training
contexts = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
# Corresponding decisions (items) taken, it can be str or int
decisions = np.array(['a', 1, 2])
# Corresponding rewards (ratings) received                     
rewards = np.array([1, 0, 1])

# Initialize the bandit. A seed is set for reproducibility and GPU usage can be switched
bandit = LinUCB(seed=42, use_gpu=True)

# Fit the model with the training data
bandit.fit(contexts, decisions, rewards)

# Predict scores for each arm (item) given a batch of contexts
bandit.predict(np.array([[1, 1, 0], [0, 1, 1]]))

Using a MAB Algorithm to generate recommendations

import numpy as np
import gobrec
# Import LinUCB as an example, it could be also LinTS or LinGreedy
from gobrec.mabs.lin_mabs import LinUCB

# A batch of contexts for training.
contexts = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
# Corresponding decisions (items) taken, it can be str or int
decisions = np.array(['a', 1, 2])
# Corresponding rewards (ratings) received
rewards = np.array([1, 0, 1])

recommender = gobrec.Recommender(
    # The recommender can use any implementation following the MABAlgo interface
    mab_algo=LinUCB(seed=42, use_gpu=True),
    # Number of items to recommend
    top_k=2
)

# Fit the model with the training data
recommender.fit(contexts, decisions, rewards)

# Recommend top_k items given a batch of contexts
recommender.recommend(np.array([[1, 1, 0], [0, 1, 1]]))

Documentation

sphinx-apidoc -o docsrc ./gobrec
make html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gobrec-0.5.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gobrec-0.5.0-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file gobrec-0.5.0.tar.gz.

File metadata

  • Download URL: gobrec-0.5.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for gobrec-0.5.0.tar.gz
Algorithm Hash digest
SHA256 01a1e7d0fe6ec69c33f4fb45236574394f7ecbd8220c65b88ffbcaa14e66880f
MD5 fcb239bd293742c5bc11f0f78b48efd9
BLAKE2b-256 7b61f264ab6e3c2886a79d0b8a016f879c34e0a6e59178c81d1e0bfaf16dd3c4

See more details on using hashes here.

File details

Details for the file gobrec-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: gobrec-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for gobrec-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb2527dbe7c6f892040af05250d5ac4df66723bb5064c5d9eb0c98fd25a3b18f
MD5 919ade0f12a750178399c289e077a6db
BLAKE2b-256 6e6b33262f8f298d34abf3670e04ee709233b9d9b3b05453ff86eb2e2ec30c83

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page