本文整理汇总了Python中vowpalwabbit.pyvw.vw函数的典型用法代码示例。如果您正苦于以下问题:Python vw函数的具体用法?Python vw怎么用?Python vw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_keys_with_list_of_values
def test_keys_with_list_of_values():
# No exception in creating and executing model with a key/list pair
model = vw(quiet=True, q=["fa", "fb"])
model.learn('1 | a b c')
prediction = model.predict(' | a b c')
assert isinstance(prediction, float)
del model
示例2: test_multilabel_prediction_type
def test_multilabel_prediction_type():
model = vw(multilabel_oaa=4, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pMULTILABELS
prediction = model.predict(' | a b c')
assert isinstance(prediction, list)
del model
示例3: initialize
def initialize(self, test, resume=False):
if self.model_class == 'lookup':
self.actor_model = {}
elif self.model_class == 'vw_python':
self.actor_model_path = self.base_folder_name + "/model.vw"
if not test:
if not resume:
self.actor_model = pyvw.vw(quiet=True, l2=self.params['l2'], loss_function=self.params['loss_function'], holdout_off=True,
f=self.actor_model_path, b=self.params['b'], lrq=self.params['lrq'], l=self.params['l'], k=True)
else:
self.actor_model = pyvw.vw("--quiet -f {0} -i {0}".format(self.actor_model_path))
else:
self.actor_model = pyvw.vw("--quiet -t -i {0}".format(self.actor_model_path))
示例4: test_prob_prediction_type
def test_prob_prediction_type():
model = vw(loss_function='logistic', csoaa_ldf='mc', probabilities=True, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pPROB
prediction = model.predict(' | a b c')
assert isinstance(prediction, float)
del model
示例5: test_action_scores_prediction_type
def test_action_scores_prediction_type():
model = vw(loss_function='logistic', csoaa_ldf='m', quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pMULTICLASS
prediction = model.predict(' | a b c')
assert isinstance(prediction, int)
del model
示例6: test_action_probs_prediction_type
def test_action_probs_prediction_type():
model = vw(cb_explore=2, ngram=2, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pACTION_PROBS
prediction = model.predict(' | a b c')
assert isinstance(prediction, list)
del model
示例7: test_scalar_prediction_type
def test_scalar_prediction_type():
model = vw(quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pSCALAR
prediction = model.predict(' | a b c')
assert isinstance(prediction, float)
del model
示例8: test_multiclass_prediction_type
def test_multiclass_prediction_type():
n = 3
model = vw(loss_function='logistic', oaa=n, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pMULTICLASS
prediction = model.predict(' | a b c')
assert isinstance(prediction, int)
del model
示例9: save_and_continue
def save_and_continue(self, thread_id, event):
if self.epochs % 1000.0 == 0 and thread_id == 1:
event.clear()
print "saving model..."
print "epochs: " + str(self.epochs)
self.actor_model.finish()
self.actor_model = pyvw.vw("--quiet --save_resume -f {0} -i {1}".format(self.actor_model_path, self.actor_model_path))
event.set()
示例10: test_action_scores_prediction_type
def test_action_scores_prediction_type():
model = vw(loss_function='logistic', csoaa_ldf='m', quiet=True)
multi_ex = [model.example('1:1 | a b c'), model.example('2:-1 | a b c')]
model.learn(multi_ex)
assert model.get_prediction_type() == model.pMULTICLASS
multi_ex = [model.example('1 | a b c'), model.example('2 | a b c')]
prediction = model.predict(multi_ex)
assert isinstance(prediction, int)
del model
示例11: test_prob_prediction_type
def test_prob_prediction_type():
model = vw(loss_function='logistic', csoaa_ldf='mc', probabilities=True, quiet=True)
multi_ex = [model.example('1:0.2 | a b c'), model.example('2:0.8 | a b c')]
model.learn(multi_ex)
assert model.get_prediction_type() == model.pPROB
multi_ex = [model.example('1 | a b c'), model.example('2 | a b c')]
prediction = model.predict(multi_ex)
assert isinstance(prediction, float)
del model
示例12: test_scalars_prediction_type
def test_scalars_prediction_type():
n = 3
model = vw(loss_function='logistic', oaa=n, probabilities=True, quiet=True)
model.learn('1 | a b c')
assert model.get_prediction_type() == model.pSCALARS
prediction = model.predict(' | a b c')
assert isinstance(prediction, list)
assert len(prediction) == n
del model
示例13: load
def load(self, verify_on_load=True):
"""
loads model file into memory (as a vw sub-process)
verify model first, then stop process if status is not active
Args:
verify_on_load (bool): flag to call verify when loading a model
"""
self.process = pyvw.vw(self.command)
super(self.__class__, self).load(verify_on_load=verify_on_load)
示例14: get_vw
def get_vw(self):
"""Factory to create a vw instance on demand
Returns
-------
pyvw.vw instance
"""
if self.vw_ is None:
self.vw_ = vw(**self.params)
# set label type
self.label_type_ = self.vw_.get_label_type()
return self.vw_
示例15: test_regressor_args
def test_regressor_args():
# load and parse external data file
data_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources', 'train.dat')
model = vw(oaa=3, data=data_file, passes=30, c=True, k=True)
assert model.predict('| feature1:2.5') == 1
# update model in memory
for _ in range(10):
model.learn('3 | feature1:2.5')
assert model.predict('| feature1:2.5') == 3
# save model
model.save('tmp.model')
del model
# load initial regressor and confirm updated prediction
new_model = vw(i='tmp.model', quiet=True)
assert new_model.predict('| feature1:2.5') == 3
del new_model
# clean up
os.remove('{}.cache'.format(data_file))
os.remove('tmp.model')