Python之nyoka:nyoka库函数的简介、安装、使用方法之详细攻略

简介: Python之nyoka:nyoka库函数的简介、安装、使用方法之详细攻略

nyoka库函数的简介


    Nyoka是一个全面支持最新PMML (PMML 4.4)标准的Python库。使用Nyoka,数据科学家可以出口大量的机器学习和深度学习从流行的Python框架PMML模型通过使用任何众多包括现成的出口商或通过创建自己的专业出口商/个人模型类型通过构造函数的调用序列。

    除了大约500 Python类,每个封面PMML标签和所有构造函数参数/属性中定义的标准,Nyoka还提供了越来越多的方便的类和函数,简化数据科学家的生活例如通过阅读或编写任何PMML文件在一行代码中你最喜欢的Python环境。

    Nyoka提供了完整的Python源代码,扩展的HTML类/函数文档,以及越来越多的Jupyter笔记本教程,帮助您熟悉Nyoka支持您使用PMML作为您最喜欢的数据科学传输文件格式的方式。


Nyoka文档:https://softwareag.github.io/nyoka/



1、Nyoka的核心模块


Statsmodels Exporter Module

Keras Exporter Module

RetinaNet Exporter Module

LightGBM Exporter Module

Pre-Processing Exporter Module

Scikit-Learn Exporter Module

XGBoost Exporter Module

ExponentialSmoothing Exporter Module

Nyoka's Pre-Processing Module

Enums Module


2、模型


(1)、基础模型


linear_model.LinearRegression

linear_model.LogisticRegression

linear_model.RidgeClassifier

linear_model.SGDClassifier

discriminant_analysis.LinearDiscriminantAnalysis

tree.DecisionTreeClassifier

tree.DecisionTreeRegressor

svm.SVC

svm.SVR

svm.LinearSVC

svm.LinearSVR

svm.OneClassSVM

naive_bayes.GaussianNB

ensemble.RandomForestRegressor

ensemble.RandomForestClassifier

ensemble.GradientBoostingRegressor

ensemble.GradientBoostingClassifier

ensemble.IsolationForest

neural_network.MLPClassifier

neural_network.MLPRegressor

neighbors.KNeighborsClassifier

neighbors.KNeighborsRegressor

cluster.KMeans

(2)、LightGBM:


LGBMClassifier

LGBMRegressor

(3)、XGBoost (version <= 0.90):


XGBClassifier

XGBRegressor

(4)、Statsmodels (version <= 0.11.1):


tsa.arima_model.ARIMA

tsa.arima.model.ARIMA (In statespace form)

tsa.statespace.SARIMAX

tsa.statespace.VARMAX

tsa.statespace.ExponentialSmoothing




nyoka库函数的安装


pip install nyoka

pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple nyoka


image.png






nyoka库函数的使用方法


1、Nyoka为每个库包含独立的导出程序,例如scikit-learn、keras、xgboost等。


library exporter

scikit-learn skl_to_pmml

xgboost xgboost_to_pmml

lightgbm lgbm_to_pmml

keras KerasToPmml

statsmodels StatsmodelsToPmml & ExponentialSmoothingToPmml

retinanet RetinanetToPmml


2、基于StandardScaler的决策树分类器案例


from sklearn.pipeline import Pipeline

from sklearn.tree import DecisionTreeClassifier

from sklearn.preprocessing import StandardScaler

pipeline_obj = Pipeline([

        ("scaler",StandardScaler()),

        ("model",DecisionTreeClassifier())

])

from sklearn.dataset import load_iris

iris_data = load_iris()

X = iris_data.data

y = iris_data.target

features = iris_data.feature_names

pipeline_obj.fit(X,y)

from nyoka import skl_to_pmml

skl_to_pmml(pipeline=pipeline_obj,col_names=features,target_name="species",pmml_f_name="decision_tree.pmml")




3、LGBMClassifier → PMML


import pandas as pd

from sklearn import datasets

from sklearn.pipeline import Pipeline

from lightgbm import LGBMRegressor,LGBMClassifier

from nyoka import lgb_to_pmml

iris = datasets.load_iris()

irisd = pd.DataFrame(iris.data,columns=iris.feature_names)

target = 'Species'

irisd[target] = iris.target

features = irisd.columns.drop(target)

#保存模型

pipeline_obj = Pipeline([ ('lgbmc',LGBMClassifier())])

pipeline_obj.fit(irisd[features],irisd[target])

lgb_to_pmml(pipeline_obj,features,target,"lgbmc_pmml.pmml")

#读入数据进行测试

auto = pd.read_csv('auto-mpg.csv')

X = auto.drop(['mpg','car name'], axis=1)

y = auto['mpg']

feature_names = [name for name in auto.columns if name not in ('mpg','car name')]

target_name='mpg'

pipeline_obj = Pipeline([ ('lgbmr',LGBMRegressor()) ])

pipeline_obj.fit(auto[feature_names],auto[target_name])

lgb_to_pmml(pipeline_obj,feature_names,target_name,"lgbmr_pmml.pmml")


4、基于nyoka库利用LGBMClassifier模型实现对iris数据集训练、保存为pmml模型并重新载入pmml模型进而实现推理


ML之nyoka:基于nyoka库利用LGBMClassifier模型实现对iris数据集训练、保存为pmml模型并重新载入pmml模型进而实现推理



相关文章
|
2天前
|
调度 开发者 网络架构
探索Python中的异步编程:深入理解asyncio库
【9月更文挑战第32天】在现代软件开发中,异步编程已成为提升性能和响应性的关键策略之一。本文将深入探讨Python的asyncio库,一个强大的异步I/O框架,它允许开发者编写单线程并发代码,同时处理多个任务而无需复杂的多线程或多进程编程。通过本文,你将学习到如何利用asyncio来构建高效、可扩展的应用程序,并了解其背后的原理和设计哲学。
7 2
|
5天前
|
安全 Python
Python量化炒股的获取数据函数—get_industry()
Python量化炒股的获取数据函数—get_industry()
13 3
|
4天前
|
数据挖掘 Python
【Python】应用:pyproj地理计算库应用
这篇博客介绍了 `pyproj` 地理计算库的应用,涵盖地理坐标系统转换与地图投影。通过示例代码展示了如何进行经纬度与UTM坐标的互转,并利用 `pyproj.Geod` 计算两点间的距离及方位角,助力地理数据分析。 安装 `pyproj`:`pip install pyproj`。更多内容欢迎关注本博客,一起学习进步! Pancake 🍰 不迷路。😉*★,°*:.☆( ̄▽ ̄)/$:*.°★* 😏
|
5天前
|
Python
Python量化炒股的获取数据函数—get_security_info()
Python量化炒股的获取数据函数—get_security_info()
12 1
|
5天前
|
Python
Python量化炒股的获取数据函数— get_billboard_list()
Python量化炒股的获取数据函数— get_billboard_list()
10 0
|
5月前
|
算法 Python 容器
Python编程 - 不调用相关choose库函数,“众数“挑选器、随机挑选器 的源码编程实现
Python编程 - 不调用相关choose库函数,“众数“挑选器、随机挑选器 的源码编程实现
71 0
|
5天前
|
算法 Python
Python编程的函数—内置函数
Python编程的函数—内置函数
10 0
|
5月前
|
算法 Python
Python编程实验四:函数的使用
Python编程实验四:函数的使用
61 0
|
5月前
|
存储 程序员 Shell
Python 进阶指南(编程轻松进阶):十、编写高效函数
Python 进阶指南(编程轻松进阶):十、编写高效函数
63 0
|
5月前
|
存储 Shell C++
零基础学会python编程——输入 / 输出函数与变量
零基础学会python编程——输入 / 输出函数与变量
137 0
下一篇
无影云桌面