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

"Attribute weight operator"

UsernameUsername Member Posts: 39 Maven
edited May 2019 in Help
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

  • IngoRMIngoRM Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder
    Hello,

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

    Cheers,
    Ingo
  • UsernameUsername Member Posts: 39 Maven
    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.
  • UsernameUsername Member Posts: 39 Maven
    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;
    }

    }
  • IngoRMIngoRM Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder
    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
  • UsernameUsername Member Posts: 39 Maven
    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.
  • UsernameUsername Member Posts: 39 Maven
    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.
  • IngoRMIngoRM Employee-RapidMiner, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,751 RM Founder
    Hi,

    the JCA arrived and we will add your extension. Thanks again and all the best,
    Ingo
Sign In or Register to comment.