The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
[SOLVED] Convert binominal to numeric?
Dear All,
I have several binomial attributes, on which I wish to run linear regression.
So I must convert these binomial attributes with values "true" and "false" to real attributes with values "1" and "0".
How can I do this?
I tried the generate attributes operator but this did not work.
I used the following settings:
attribute name: myNewAtt
functional expression: if(myAtt == true, 1, 0)
Even though this expression is functionally correct, it always returns 0.
Best regards,
Wessel
I have several binomial attributes, on which I wish to run linear regression.
So I must convert these binomial attributes with values "true" and "false" to real attributes with values "1" and "0".
How can I do this?
I tried the generate attributes operator but this did not work.
I used the following settings:
attribute name: myNewAtt
functional expression: if(myAtt == true, 1, 0)
Even though this expression is functionally correct, it always returns 0.
Best regards,
Wessel
0
Answers
using operators
1. replace (replace all true values to 1)
2. replace (replace all false values to 0)
3. parse numbers
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.1.017">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.1.017" expanded="true" name="Process">
<process expanded="true" height="642" width="778">
<operator activated="true" class="replace" compatibility="5.1.017" expanded="true" height="76" name="Replace" width="90" x="59" y="140">
<parameter key="attribute_filter_type" value="subset"/>
<parameter key="attributes" value="|cluster_2|cluster_1|cluster_0"/>
<parameter key="replace_what" value="true"/>
<parameter key="replace_by" value="1"/>
</operator>
<operator activated="true" class="replace" compatibility="5.1.017" expanded="true" height="76" name="Replace (2)" width="90" x="187" y="85">
<parameter key="attribute_filter_type" value="subset"/>
<parameter key="attributes" value="|cluster_2|cluster_1|cluster_0"/>
<parameter key="replace_what" value="false"/>
<parameter key="replace_by" value="0"/>
</operator>
<operator activated="true" class="parse_numbers" compatibility="5.1.017" expanded="true" height="76" name="Parse Numbers" width="90" x="315" y="30">
<parameter key="attribute_filter_type" value="subset"/>
<parameter key="attributes" value="|cluster_2|cluster_1|cluster_0"/>
</operator>
<connect from_op="Replace" from_port="example set output" to_op="Replace (2)" to_port="example set input"/>
<connect from_op="Replace (2)" from_port="example set output" to_op="Parse Numbers" to_port="example set input"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
</process>
</operator>
</process>
Two additional solutions:
1) Use Weka's Linear Regression Operator. It will code the binomial attributes for you automatically. This is sooooo convenient.
2) Use the "Nominal to Numerical" Operator and select Dummy Coding. You have to define then for each binomial variable a "comparison group" which will get coded 0. According to your message, the comparison group will be false.
Regards,
\E
Here's a example that uses the Golf dataset: