如何通过组合 Weka 中现有的 2 个属性来创建新属性?
How to create new attribute by combining existing 2 attribute in Weka?
我是 Weka 的新手,发现关于过滤器功能的文档很少。
实际上,我有 2 个属性,即 profit
、cost
。我想创建一个新的属性名称 result
来比较 profit
和 cost
属性,并且对于每个行值,result
标签将是 gain
如果 profit
> cost
,否则标签会是'loss'.
我正在使用 Weka Explorer UI。我尝试了 Copy
和 MergeTwoValue
过滤器,但似乎无法执行比较步骤。正确的步骤是什么?
这样的比较可以使用 MathExpression 过滤器作为过滤器处理管道的一部分,使用 ifelse
构造。但是,MathExpression 不允许您使用标签,但您可以使用指标标签 0
或 1
来指示是盈利还是亏损。
MultiFilter
|
+- Add (we insert a new numeric attribute, all missing values)
|
+- ReplaceMissingWithUserConstant (MathExpression skips missing values, hence replacing them in our new attribute)
|
+- MathExpression (the actual comparison between the two attributes)
|
+- NumericToNominal (to turn the numeric 0/1 values into labels)
我将演示如何使用 bolts UCI 数据集构建此管道,该数据集具有以下属性:
1 RUN numeric
2 SPEED1 numeric
3 TOTAL numeric
4 SPEED2 numeric
5 NUMBER2 numeric
6 SENS numeric
7 TIME numeric
8 T20BOLT numeric
对于这个例子,我想比较 SENS
和 TIME
,创建一个指标是否 SENS > TIME
。
多重过滤器
MultiFilter instance combines all our sub-filters into a single filter setup. That way you can easily apply, extend it or use it within a FilteredClassifier 设置。
添加
首先,我们将在索引 8
处使用 Add 过滤器添加一个属性,这会将 class 属性推送到位置 9
,并为其命名SENS>TIME
(你可以给它起任何你想要的名字):
weka.filters.unsupervised.attribute.Add -N SENS>TIME -C 8
ReplaceMissingWithUserConstant
接下来,我们使用 ReplaceMissingValueUserConstant 过滤器将属性(索引 8
)中的缺失值替换为虚拟值,例如 -1
。不幸的是,这是必要的,因为 MathExpression
不对缺失值进行操作。
weka.filters.unsupervised.attribute.ReplaceMissingWithUserConstant -A 8 -R -1 -F "yyyy-MM-dd\'T\'HH:mm:ss"
数学表达式
设置阶段后,我们现在可以使用 MathExpression 来使用表达式 ifelse(A6>A7,1,0)
:
来填充我们的比较
weka.filters.unsupervised.attribute.MathExpression -E ifelse(A6>A7,1,0) -V -R 8
如果属性 6
(SENS
) 大于属性 7
(TIME
),则插入一个 1
,否则插入一个 0
.
数值转名义
使用 NumericToNominal 过滤器,我们会将比较属性中的数字指标转换为标称标签:
weka.filters.unsupervised.attribute.NumericToNominal -R 8
奖金
如果您想使用标签 gain
/loss
而不是 1
/0
,则可以在管道结束。
我是 Weka 的新手,发现关于过滤器功能的文档很少。
实际上,我有 2 个属性,即 profit
、cost
。我想创建一个新的属性名称 result
来比较 profit
和 cost
属性,并且对于每个行值,result
标签将是 gain
如果 profit
> cost
,否则标签会是'loss'.
我正在使用 Weka Explorer UI。我尝试了 Copy
和 MergeTwoValue
过滤器,但似乎无法执行比较步骤。正确的步骤是什么?
这样的比较可以使用 MathExpression 过滤器作为过滤器处理管道的一部分,使用 ifelse
构造。但是,MathExpression 不允许您使用标签,但您可以使用指标标签 0
或 1
来指示是盈利还是亏损。
MultiFilter
|
+- Add (we insert a new numeric attribute, all missing values)
|
+- ReplaceMissingWithUserConstant (MathExpression skips missing values, hence replacing them in our new attribute)
|
+- MathExpression (the actual comparison between the two attributes)
|
+- NumericToNominal (to turn the numeric 0/1 values into labels)
我将演示如何使用 bolts UCI 数据集构建此管道,该数据集具有以下属性:
1 RUN numeric
2 SPEED1 numeric
3 TOTAL numeric
4 SPEED2 numeric
5 NUMBER2 numeric
6 SENS numeric
7 TIME numeric
8 T20BOLT numeric
对于这个例子,我想比较 SENS
和 TIME
,创建一个指标是否 SENS > TIME
。
多重过滤器
MultiFilter instance combines all our sub-filters into a single filter setup. That way you can easily apply, extend it or use it within a FilteredClassifier 设置。
添加
首先,我们将在索引 8
处使用 Add 过滤器添加一个属性,这会将 class 属性推送到位置 9
,并为其命名SENS>TIME
(你可以给它起任何你想要的名字):
weka.filters.unsupervised.attribute.Add -N SENS>TIME -C 8
ReplaceMissingWithUserConstant
接下来,我们使用 ReplaceMissingValueUserConstant 过滤器将属性(索引 8
)中的缺失值替换为虚拟值,例如 -1
。不幸的是,这是必要的,因为 MathExpression
不对缺失值进行操作。
weka.filters.unsupervised.attribute.ReplaceMissingWithUserConstant -A 8 -R -1 -F "yyyy-MM-dd\'T\'HH:mm:ss"
数学表达式
设置阶段后,我们现在可以使用 MathExpression 来使用表达式 ifelse(A6>A7,1,0)
:
weka.filters.unsupervised.attribute.MathExpression -E ifelse(A6>A7,1,0) -V -R 8
如果属性 6
(SENS
) 大于属性 7
(TIME
),则插入一个 1
,否则插入一个 0
.
数值转名义
使用 NumericToNominal 过滤器,我们会将比较属性中的数字指标转换为标称标签:
weka.filters.unsupervised.attribute.NumericToNominal -R 8
奖金
如果您想使用标签 gain
/loss
而不是 1
/0
,则可以在管道结束。