當前位置: 首頁>>代碼示例>>Python>>正文


Python sklearn_porter.Porter類代碼示例

本文整理匯總了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;未經允許,請勿轉載。