【发布时间】:2020-01-19 16:02:30
【问题描述】:
我正在尝试编写一个种子功能,它会产生 reward if place == 1 else 0。
place 和reward 都是ft.variable_types.Numeric:
Entity: results
Variables:
id (dtype: index)
place (dtype: numeric)
reward (dtype: numeric)
我尝试了以下替代方法,但没有成功:
备选方案 1
roi = (ft.Feature(es['results']['reward'])
if (ft.Feature(es['results']['place']) == 1)
else 0).rename('roi')
产生AssertionError: Column "roi" missing frome dataframe
生成特征时。
备选方案 2
roi = ((ft.Feature(es['results']['place']) == 1) *
ft.Feature(es['results']['reward'])).rename('roi')
在分配种子特征时产生AssertionError: Provided inputs don't match input type requirements。
替代方案 2 应该可以在 Python 中使用:
>>> True * 3.14
3.14
>>> False * 3.14
0.0
完整的堆栈跟踪:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-211-94dd07d98076> in <module>()
23
24
---> 25 roi = ((ft.Feature(es['results']['place']) == 1) * ft.Feature(es['results']['reward'])).rename('roi')
~/dev/venv/lib/python3.6/site-packages/featuretools/feature_base/feature_base.py in __mul__(self, other)
287 def __mul__(self, other):
288 """Multiply by other"""
--> 289 return self._handle_binary_comparision(other, primitives.MultiplyNumeric, primitives.MultiplyNumericScalar)
290
291 def __rmul__(self, other):
~/dev/venv/lib/python3.6/site-packages/featuretools/feature_base/feature_base.py in _handle_binary_comparision(self, other, Primitive, PrimitiveScalar)
230 def _handle_binary_comparision(self, other, Primitive, PrimitiveScalar):
231 if isinstance(other, FeatureBase):
--> 232 return Feature([self, other], primitive=Primitive)
233
234 return Feature([self], primitive=PrimitiveScalar(other))
~/dev/venv/lib/python3.6/site-packages/featuretools/feature_base/feature_base.py in __new__(self, base, entity, groupby, parent_entity, primitive, use_previous, where)
755 primitive=primitive,
756 groupby=groupby)
--> 757 return TransformFeature(base, primitive=primitive)
758
759 raise Exception("Unrecognized feature initialization")
~/dev/venv/lib/python3.6/site-packages/featuretools/feature_base/feature_base.py in __init__(self, base_features, primitive, name)
660 relationship_path=RelationshipPath([]),
661 primitive=primitive,
--> 662 name=name)
663
664 @classmethod
~/dev/venv/lib/python3.6/site-packages/featuretools/feature_base/feature_base.py in __init__(self, entity, base_features, relationship_path, primitive, name, names)
56 self._names = names
57
---> 58 assert self._check_input_types(), ("Provided inputs don't match input "
59 "type requirements")
60
AssertionError: Provided inputs don't match input type requirements
【问题讨论】:
-
备选方案 2 应该可以工作。你能做
print(es["results"])并分享输出吗? -
请分享完整的堆栈跟踪
-
@MaxKanter 我已经包含了堆栈跟踪和类型信息。
-
这里的问题实际上是乘法原语只支持数字输入,而它可能也应该允许布尔值。我在 Featuretools 中创建了一个问题供我们解决。应该在下一个版本之前完成。 github.com/Featuretools/featuretools/issues/752
标签: pandas featuretools