• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sklearn_porter.Porter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sklearn_porter.Porter的典型用法代码示例。如果您正苦于以下问题:Python Porter类的具体用法?Python Porter怎么用?Python Porter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Porter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _port_estimator

 def _port_estimator(self):
     self.estimator.fit(self.X, self.y)
     Shell.call('rm -rf tmp')
     Shell.call('mkdir tmp')
     filename = self.tmp_fn + '.rb'
     path = os.path.join('tmp', filename)
     with open(path, 'w') as f:
         porter = Porter(self.estimator, language=self.LANGUAGE)
         out = porter.export(class_name='Brain', method_name='foo')
         f.write(out)
开发者ID:nok,项目名称:scikit-learn-model-porting,代码行数:10,代码来源:Ruby.py


示例2: main

def main():
    args = parse_args(sys.argv[1:])

    # Check input data:
    pkl_file_path = str(args.get('input'))
    if not isfile(pkl_file_path):
        exit_msg = 'No valid estimator in pickle ' \
                   'format was found at \'{}\'.'.format(pkl_file_path)
        sys.exit('Error: {}'.format(exit_msg))

    # Load data:
    estimator = joblib.load(pkl_file_path)

    # Determine the target programming language:
    language = str(args.get('language'))  # with default language
    languages = ['c', 'java', 'js', 'go', 'php', 'ruby']
    for key in languages:
        if args.get(key):  # found explicit assignment
            language = key
            break

    # Define destination path:
    dest_dir = str(args.get('to'))
    if dest_dir == '' or not isdir(dest_dir):
        dest_dir = pkl_file_path.split(sep)
        del dest_dir[-1]
        dest_dir = sep.join(dest_dir)

    # Port estimator:
    try:
        class_name = args.get('class_name')
        method_name = args.get('method_name')
        with_export = bool(args.get('export'))
        with_checksum = bool(args.get('checksum'))
        porter = Porter(estimator, language=language)
        output = porter.export(class_name=class_name, method_name=method_name,
                               export_dir=dest_dir, export_data=with_export,
                               export_append_checksum=with_checksum,
                               details=True)
    except Exception as exception:
        # Catch any exception and exit the process:
        sys.exit('Error: {}'.format(str(exception)))
    else:
        # Print transpiled estimator to the console:
        if bool(args.get('pipe', False)):
            print(output.get('estimator'))
            sys.exit(0)

        only_data = bool(args.get('data'))
        if not only_data:
            filename = output.get('filename')
            dest_path = dest_dir + sep + filename
            # Save transpiled estimator:
            with open(dest_path, 'w') as file_:
                file_.write(output.get('estimator'))
开发者ID:nok,项目名称:scikit-learn-model-porting,代码行数:55,代码来源:__main__.py


示例3: _port_estimator

 def _port_estimator(self):
     self.estimator.fit(self.X, self.y)
     Shell.call('rm -rf tmp')
     Shell.call('mkdir tmp')
     path = os.path.join('.', 'tmp', self.tmp_fn + '.go')
     output = os.path.join('.', 'tmp', self.tmp_fn)
     with open(path, 'w') as f:
         porter = Porter(self.estimator, language=self.LANGUAGE)
         out = porter.export(class_name='Brain', method_name='foo')
         f.write(out)
     cmd = 'go build -o {} {}'.format(output, path)
     Shell.call(cmd)
开发者ID:nok,项目名称:scikit-learn-model-porting,代码行数:12,代码来源:Go.py


示例4: _port_estimator

 def _port_estimator(self, export_data=False, embed_data=False):
     self.estimator.fit(self.X, self.y)
     Shell.call('rm -rf tmp')
     Shell.call('mkdir tmp')
     with open(self.tmp_fn, 'w') as f:
         porter = Porter(self.estimator, language=self.LANGUAGE)
         if export_data:
             out = porter.export(class_name='Brain',
                                 method_name='foo',
                                 export_data=True,
                                 export_dir='tmp')
         else:
             out = porter.export(class_name='Brain',
                                 method_name='foo',
                                 embed_data=embed_data)
         f.write(out)
开发者ID:nok,项目名称:scikit-learn-model-porting,代码行数:16,代码来源:JavaScript.py


示例5: Porter

# %% [markdown]
# ### Train classifier

# %%
from sklearn import svm

clf = svm.NuSVC(gamma=0.001, kernel='rbf', random_state=0)
clf.fit(X, y)

# %% [markdown]
# ### Transpile classifier

# %%
from sklearn_porter import Porter

porter = Porter(clf, language='js')
output = porter.export()

print(output)

# %% [markdown]
# ### Run classification in JavaScript

# %%
# Save classifier:
# with open('NuSVC.js', 'w') as f:
#     f.write(output)

# Run classification:
# if hash node 2/dev/null; then
#     node NuSVC.js 1 2 3 4
开发者ID:nok,项目名称:scikit-learn-model-porting,代码行数:31,代码来源:basics.pct.py


示例6: RandomForestClassifier

# ### Train classifier

# %%
from sklearn.ensemble import RandomForestClassifier

clf = RandomForestClassifier(n_estimators=15, max_depth=None,
                             min_samples_split=2, random_state=0)
clf.fit(X, y)

# %% [markdown]
# ### Transpile classifier

# %%
from sklearn_porter import Porter

porter = Porter(clf, language='java')
output = porter.export(embed_data=True)

print(output)

# %% [markdown]
# ### Run classification in Java

# %%
# Save classifier:
# with open('RandomForestClassifier.java', 'w') as f:
#     f.write(output)

# Compile model:
# $ javac -cp . RandomForestClassifier.java
开发者ID:nok,项目名称:scikit-learn-model-porting,代码行数:30,代码来源:basics_embedded.pct.py


示例7: Porter

# %% [markdown]
# ### Train classifier

# %%
from sklearn.tree import tree

clf = tree.DecisionTreeClassifier()
clf.fit(X, y)

# %% [markdown]
# ### Transpile classifier

# %%
from sklearn_porter import Porter

porter = Porter(clf, language='java')
output = porter.export(export_data=True)

print(output)

# %% [markdown]
# ### Run classification in Java

# %%
# Save classifier:
# with open('DecisionTreeClassifier.java', 'w') as f:
#     f.write(output)

# Check model data:
# $ cat data.json
开发者ID:nok,项目名称:scikit-learn-model-porting,代码行数:30,代码来源:basics_imported.pct.py



注:本文中的sklearn_porter.Porter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python experiments.run_configuration函数代码示例发布时间:2022-05-27
下一篇:
Python sklearn_pandas.DataFrameMapper类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap