"Attribute weight operator"

Username
Username New Altair Community Member
edited November 5 in Community Q&A
Hi,

is there an operator that assigns weights to attributes via the attribute name (maybe with regular expressions)? I looked at the docs but I didn't find anything. There's the InteractiveAttributeWeighting operator but I have too many features (text classification). If there's not such an operator I will write one myself. This should actually be pretty easy.

Thanks
Tagged:

Answers

  • IngoRM
    IngoRM New Altair Community Member
    Hello,

    nice idea but there is currently no operator for this, sorry.

    Cheers,
    Ingo
  • Username
    Username New Altair Community Member
    mierswa wrote:

    Hello,

    nice idea but there is currently no operator for this, sorry.

    Cheers,
    Ingo
    Thanks for your answer. I will write one myself then.
  • Username
    Username New Altair Community Member
    For anybody who's interested:
    import java.util.List;
    import java.util.regex.Pattern;
    import java.util.regex.PatternSyntaxException;

    import com.rapidminer.example.Attribute;
    import com.rapidminer.example.AttributeWeights;
    import com.rapidminer.example.ExampleSet;
    import com.rapidminer.operator.OperatorDescription;
    import com.rapidminer.operator.OperatorException;
    import com.rapidminer.operator.features.weighting.AbstractWeighting;
    import com.rapidminer.parameter.ParameterType;
    import com.rapidminer.parameter.ParameterTypeDouble;
    import com.rapidminer.parameter.ParameterTypeList;

    public class AttributeWeighting extends AbstractWeighting {

    private static final String WEIGHTING_PARAMETER = "regex";

    public AttributeWeighting(OperatorDescription description) {
    super(description);
    }

    @Override
    public AttributeWeights calculateWeights(ExampleSet exampleSet) throws OperatorException {
    AttributeWeights attributeWeights = new AttributeWeights();
    for (Attribute attribute : exampleSet.getAttributes()) {
    attributeWeights.setWeight(attribute.getName(), 1);
    }
    @SuppressWarnings("unchecked")
    List<Object[]> list = getParameterList(WEIGHTING_PARAMETER);
    for (Object[] entry : list) {
    String regex = (String) entry[0];
    Double weighting = (Double) entry[1];
    if (regex != null && weighting != null) {
    try {
    Pattern pattern = Pattern.compile(regex);
    for (Attribute attribute : exampleSet.getAttributes()) {
    String attributeName = attribute.getName();
    if (pattern.matcher(attributeName).matches()) {
    attributeWeights.setWeight(attributeName, weighting);
    }
    }
    } catch (PatternSyntaxException e) {
    logWarning(regex + " is not a valid regular expression!");
    }
    }
    }
    return attributeWeights;
    }

    @Override
    public List<ParameterType> getParameterTypes() {
    List<ParameterType> parameters = super.getParameterTypes();
    ParameterType weighting = new ParameterTypeList(WEIGHTING_PARAMETER, "Regex -> Weighting", new ParameterTypeDouble("weighting", "weighting", 0, Double.MAX_VALUE, false));
    weighting.setExpert(false);
    parameters.add(weighting);
    return parameters;
    }

    }
  • IngoRM
    IngoRM New Altair Community Member
    Wow, that's fast  8)

    I would really like to add your contribution to the official release if you do not object. If this is ok to you, I would like to ask if you could sign the joint copyright assignment (known from Open Office, basically it only states that both parties, i.e. you and Rapid-I, have the copyright for the contribution) and send it to us. Then we are able to add the new operator to the official release. If you like to contribute, just download and sign the JCA under

    http://rapid-i.com/component/option,com_docman/task,doc_download/gid,26/Itemid,62/

    Since we have to adapt the code a bit anyway to stick to our coding standards, this is of course not too much of an issue but I would like to get things right first.

    Cheers,
    Ingo
  • Username
    Username New Altair Community Member
    mierswa wrote:

    Wow, that's fast  8)

    I would really like to add your contribution to the official release if you do not object. If this is ok to you, I would like to ask if you could sign the joint copyright assignment (known from Open Office, basically it only states that both parties, i.e. you and Rapid-I, have the copyright for the contribution) and send it to us. Then we are able to add the new operator to the official release. If you like to contribute, just download and sign the JCA under

    http://rapid-i.com/component/option,com_docman/task,doc_download/gid,26/Itemid,62/

    Since we have to adapt the code a bit anyway to stick to our coding standards, this is of course not too much of an issue but I would like to get things right first.

    Cheers,
    Ingo
    Ok, I will sign the JCA and send it via old fashioned mail in the next days.
  • Username
    Username New Altair Community Member
    Username wrote:

    Ok, I will sign the JCA and send it via old fashioned mail in the next days.
    The JCA should arrive today or tomorrow.
  • IngoRM
    IngoRM New Altair Community Member
    Hi,

    the JCA arrived and we will add your extension. Thanks again and all the best,
    Ingo