机器学习模型实用程序

bavard-ml-common的Python项目详细描述


巴瓦德ml普通

Web服务示例

importtypingastfromsklearn.datasetsimportload_irisfromsklearn.treeimportDecisionTreeClassifierimportuvicornfrombavard_ml_common.mlops.web_serviceimportendpoint,WebServiceclassDTModel(WebService):"""    A machine learning model that can turn into a web service.    """def__init__(self)->None:self._dt=DecisionTreeClassifier()self._fitted=Falsedeffit(self,X,y)->None:self._dt.fit(X,y)self._fitted=True# Type annotations are required for all `@endpoint` method arguments.@endpointdefpredict(self,X:t.List[t.List[float]]):assertself._fittedreturnself._dt.predict(X).tolist()@endpointdeffeature_importances(self)->list:assertself._fittedreturnself._dt.feature_importances_.tolist()# Fit a ML model on a dataset.iris=load_iris()X=iris.datay=iris.targetmodel=DTModel()model.fit(X,y)# Convert the model into a `fastapi` web service.api=model.to_app()# Run the web service.uvicorn.run(api,host="0.0.0.0",use_colors=True,log_level="debug")# The fitted model is now available at 0.0.0.0:8000/,# with a `/predict` endpoint and a `/feature_importances` endpoint.# API documentation for the fitted model is at a `/docs` endpoint.

在当地发展

安装依赖项:

^{pr2}$

然后,使用pytest运行测试:

python3 -m unittest

释放程序包

发布包由CI自动处理,但必须采取三个步骤才能触发成功的释放:

  1. setup.py中的VERSION变量增加到所需的新版本(例如VERSION="1.1.1"
  2. 使用提交并标记repo,该值与您在VERSION变量中填充的值完全相同(例如git tag 1.1.1
  3. 将commit和tag推送到remote。这些可以一起使用:git push --atomic origin <branch name> <tag>

一旦推送commit和标记,CI将使用该版本将包发布给pypi。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带有字符串的java JNA调用与带有字节[]的java JNA调用的行为不同   java基于键列表获取子映射   重启后永久增加java堆大小?   JavaHTTPS服务器:相互SSL身份验证   java为什么接受接口的方法会拒绝该接口的实现?   片段中的java视图无法应用于()   ms access Java SQL更新命令不工作   java将web服务自动打包和部署到Oracle Application Server 10g   java有没有办法在安卓 studio中为安卓时钟设置多个警报?   位于FTP服务器上的文件上的Java校验和md5   在Java中创建类时遇到问题。有些方法不太确定   java错误:在类chrome\u驱动程序中找不到主方法   通用海图(Javascript\Java)