本文整理匯總了Python中sklearn_porter.Porter.export方法的典型用法代碼示例。如果您正苦於以下問題:Python Porter.export方法的具體用法?Python Porter.export怎麽用?Python Porter.export使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sklearn_porter.Porter
的用法示例。
在下文中一共展示了Porter.export方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _port_estimator
# 需要導入模塊: from sklearn_porter import Porter [as 別名]
# 或者: from sklearn_porter.Porter import export [as 別名]
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)
示例2: _port_estimator
# 需要導入模塊: from sklearn_porter import Porter [as 別名]
# 或者: from sklearn_porter.Porter import export [as 別名]
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)
示例3: main
# 需要導入模塊: from sklearn_porter import Porter [as 別名]
# 或者: from sklearn_porter.Porter import export [as 別名]
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'))
示例4: _port_estimator
# 需要導入模塊: from sklearn_porter import Porter [as 別名]
# 或者: from sklearn_porter.Porter import export [as 別名]
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)
示例5: Porter
# 需要導入模塊: from sklearn_porter import Porter [as 別名]
# 或者: from sklearn_porter.Porter import export [as 別名]
# ### 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
# fi
示例6: RandomForestClassifier
# 需要導入模塊: from sklearn_porter import Porter [as 別名]
# 或者: from sklearn_porter.Porter import export [as 別名]
# %%
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
# Run classification:
示例7: Porter
# 需要導入模塊: from sklearn_porter import Porter [as 別名]
# 或者: from sklearn_porter.Porter import export [as 別名]
# ### 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
# Download dependencies: