Welcome to Acton’s documentation!¶
Contents:
acton¶
acton package¶
Subpackages¶
acton.proto package¶
Submodules¶
acton.proto.io module¶
Functions for reading/writing to protobufs.
-
acton.proto.io.
get_ndarray
(data: list, shape: tuple, dtype: str) → <MagicMock id='139822700085600'>[source]¶ Converts a list of values into an array.
Parameters: - data – Raw array data.
- shape – Shape of the resulting array.
- dtype – Data type of the resulting array.
Returns: Array with the given data, shape, and dtype.
Return type: numpy.ndarray
-
acton.proto.io.
read_metadata
(file: typing.Union[str, typing.BinaryIO]) → bytes[source]¶ Reads metadata from a protobufs file.
Parameters: file – Path to binary file, or file itself. Returns: Metadata. Return type: bytes
-
acton.proto.io.
read_proto
()[source]¶ Reads a protobuf from a .proto file.
Parameters: - path – Path to the .proto file.
- Proto – Protocol message class (from the generated protobuf module).
Returns: The parsed protobuf.
Return type: GeneratedProtocolMessageType
-
acton.proto.io.
read_protos
(file: typing.Union[str, typing.BinaryIO], Proto: <MagicMock id='139822700045088'>) → <MagicMock name='mock()' id='139822700095976'>[source]¶ Reads many protobufs from a file.
Parameters: - file – Path to binary file, or file itself.
- Proto – Protocol message class (from the generated protobuf module).
Yields: GeneratedProtocolMessageType – A parsed protobuf.
acton.proto.predictors_pb2 module¶
acton.proto.wrappers module¶
Module contents¶
Submodules¶
acton.acton module¶
acton.cli module¶
acton.database module¶
acton.kde_predictor module¶
A predictor that uses KDE to classify instances.
-
class
acton.kde_predictor.
KDEClassifier
(bandwidth=1.0)[source]¶ Bases:
BaseEstimator
,ClassifierMixin
A classifier using kernel density estimation to classify instances.
-
fit
(X, y)[source]¶ Fits kernel density models to the data.
Parameters: - X (array_like, shape (n_samples, n_features)) – List of n_features-dimensional data points. Each row corresponds to a single data point.
- y (array-like, shape (n_samples,)) – Target vector relative to X.
-
acton.labellers module¶
acton.plot module¶
acton.predictors module¶
acton.recommenders module¶
Module contents¶
Developer Documentation¶
Contributing¶
We accept pull requests on GitHub. Contributions must be PEP8 compliant and pass
formatting and function tests in the test script /test
.
Adding a New Predictor¶
A predictor is a class that implements acton.predictors.Predictor
. Adding a
new predictor amounts to implementing a subclass of Predictor
and
registering it in acton.predictors.PREDICTORS
.
Predictors must implement:
__init__(db: acton.database.Database, *args, **kwargs)
, which stores a reference to the database (and does any other initialisation).fit(ids: Iterable[int])
, which takes an iterable of IDs and fits a model to the associated features and labels,predict(ids: Sequence[int]) -> numpy.ndarray
, which takes a sequence of IDs and predicts the associated labels.reference_predict(ids: Sequence[int]) -> numpy.ndarray
, which behaves the same aspredict
but uses the best possible model.
Predictors should store data-based values such as the model in attributes ending in an underscore, e.g. self.model_
.
Why Does Acton Use Predictor?¶
Acton makes use of Predictor
classes, which are often just wrappers for
scikit-learn classes. This raises the question: Why not just use scikit-learn
classes?
This design decision was made because Acton must support predictors that do not fit the scikit-learn API, and so using scikit-learn predictors directly would mean that there is no unified API for predictors. An example of where Acton diverges from scikit-learn is that scikit-learn does not support multiple labellers.
Adding a New Recommender¶
A recommender is a class that implements acton.recommenders.Recommender
. Adding a new recommender amounts to implementing a subclass of Recommender
and registering it in acton.recommenders.RECOMMENDERS
.
Recommenders must implement:
__init__(db: acton.database.Database, *args, **kwargs)
, which stores a reference to the database (and does any other initialisation).recommend(ids: Iterable[int], predictions: numpy.ndarray, n: int=1, diversity: float=0.5)` -> Sequence[int]
, which recommendsn
IDs from the given IDs based on the associated predictions.