跳转到主要内容

用于与在线ML river服务器交互的Python客户端

项目描述

River API客户端

PyPI version

这是一个为django-river-ml创建的API客户端,旨在方便与提供river模型(学习、预测等)的在线ML服务器交互。它目前不提供终端或命令行客户端,但可以从Python中使用,如果有一个很好的用例来添加命令行交互集,也可以添加。

快速入门

假设您有一个运行的服务器实现了与django-river-ml相同的空间,您可以执行以下操作。请注意,如果您的服务器需要身份验证,您可以生成一个令牌并将其导出到

export RIVER_ML_USER=dinosaur
export RIVER_ML_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

然后执行以下示例。

from river import datasets
from river import linear_model
from river import preprocessing

from riverapi.main import Client


def main():

    # This is the default, just to show how to customize
    cli = Client("http://localhost:8000")

    # Basic server info (usually no auth required)
    cli.info()

    # Upload a model
    model = preprocessing.StandardScaler() | linear_model.LinearRegression()

    # Save the model name for other endpoint interaction
    model_name = cli.upload_model(model, "regression")
    print("Created model %s" % model_name)

    # Train on some data
    for x, y in datasets.TrumpApproval().take(100):
        cli.learn(model_name, x=x, y=y)

    # Get the model (this is a json representation)
    model_json = cli.get_model_json(model_name)
    model_json

    # Saves to model-name>.pkl in pwd unless you provide a second arg, dest
    cli.download_model(model_name)

    # Make predictions
    for x, y in datasets.TrumpApproval().take(10):
        res = cli.predict(model_name, x=x)
        print(res)

    # By default the server will generate an identifier on predict that you can
    # later use to label it. Let's do that for the last predict call!
    identifier = res['identifier']

    # Let's pretend we now have a label Y for the data we didn't before.
    # The identifier is going to allow the server to find the features,
    # x, and we just need to do:
    res = cli.label(label=y, identifier=identifier, model_name=model_name)
    print(res)
    # Note that model_name is cached too, and we provide it here just 
    # to ensure the identifier is correctly associated.

    # Get stats and metrics for the model
    cli.stats(model_name)
    cli.metrics(model_name)

    # Get all models
    print(cli.models())

    # Stream events
    for event in cli.stream_events():
        print(event)

    # Stream metrics
    for event in cli.stream_metrics():
        print(event)

    # Delete the model
    cli.delete_model(model_name)

if __name__ == "__main__":
    main()

贡献者

我们使用all-contributors工具生成下面的贡献者图形。


Vanessasaurus

💻

许可证

此代码根据MPL 2.0LICENSE授权。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

riverapi-0.0.21.tar.gz (17.3 kB 查看哈希值)

上传时间 源代码

构建分发

riverapi-0.0.21-py3-none-any.whl (17.2 kB 查看哈希值)

上传时间 Python 3