本文整理匯總了Python中more_itertools.first_true方法的典型用法代碼示例。如果您正苦於以下問題:Python more_itertools.first_true方法的具體用法?Python more_itertools.first_true怎麽用?Python more_itertools.first_true使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類more_itertools
的用法示例。
在下文中一共展示了more_itertools.first_true方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_hyperparam_byname
# 需要導入模塊: import more_itertools [as 別名]
# 或者: from more_itertools import first_true [as 別名]
def get_hyperparam_byname(name: str, gbdt_type: str = 'lgbm', with_metadata: bool = False) -> Dict:
"""
Get a hyperparameter by parameter name
Args:
name:
The name of parameter (e.g. "ieee-2019-10th").
gbdt_type:
The type of gbdt library. ``lgbm``, ``cat``, ``xgb`` can be used.
with_metadata:
When set to True, parameters are wrapped by metadata dictionary which contains information about
source URL, competition name etc.
Returns:
A hyperparameter dictionary.
"""
param_table = _get_table(gbdt_type)
found = first_true(param_table, pred=lambda x: x['name'] == name)
if found is None:
raise RuntimeError('Hyperparameter {} not found.'.format(name))
return _return(found, with_metadata)
示例2: test_something_true
# 需要導入模塊: import more_itertools [as 別名]
# 或者: from more_itertools import first_true [as 別名]
def test_something_true(self):
"""Test with no keywords"""
self.assertEqual(mi.first_true(range(10)), 1)
示例3: test_nothing_true
# 需要導入模塊: import more_itertools [as 別名]
# 或者: from more_itertools import first_true [as 別名]
def test_nothing_true(self):
"""Test default return value."""
self.assertIsNone(mi.first_true([0, 0, 0]))
示例4: test_default
# 需要導入模塊: import more_itertools [as 別名]
# 或者: from more_itertools import first_true [as 別名]
def test_default(self):
"""Test with a default keyword"""
self.assertEqual(mi.first_true([0, 0, 0], default='!'), '!')
示例5: test_pred
# 需要導入模塊: import more_itertools [as 別名]
# 或者: from more_itertools import first_true [as 別名]
def test_pred(self):
"""Test with a custom predicate"""
self.assertEqual(
mi.first_true([2, 4, 6], pred=lambda x: x % 3 == 0), 6
)
示例6: _get_hyperparam_byname
# 需要導入模塊: import more_itertools [as 別名]
# 或者: from more_itertools import first_true [as 別名]
def _get_hyperparam_byname(param_table: List[Dict], name: str, with_metadata: bool):
found = first_true(param_table, pred=lambda x: x['name'] == name)
if found is None:
raise RuntimeError('Hyperparameter {} not found.'.format(name))
if with_metadata:
return found
else:
return found['parameters']