本文整理汇总了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)
示例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'))
示例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)
示例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)
示例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
示例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
示例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