Categories

Versions

Format Numbers (AI Studio Core)

Synopsis

This operator reformats the selected numerical attributes according to the specified format and changes the attributes to nominal.

Description

This operator parses numerical values and formats them into the specified format. The format is specified by the format type parameter. It supports different kinds of number formats including integers (e.g. 123), fixed-point numbers (e.g. 123.4), scientific notation (e.g. 1.23E4), percentages (e.g. 12%), and currency amounts (e.g. $123). Please note that this operator only works on numerical attributes and the result will be in any case a nominal attribute even if the resulting format is a number which can be parsed again.

If the format type parameter is set to 'pattern', the pattern parameter is used for defining the format. If two different formats for positive and negative numbers should be used, those formats can be defined by separating them by a semi-colon ';'. The pattern parameter provides a lot of flexibility for defining the pattern. Important structures that can be used for defining a pattern are listed below. The structures in brackets are optional.

  • pattern := subpattern{;subpattern}
  • subpattern := {prefix}integer{.fraction}{suffix}
  • prefix := any character combination including whitespace
  • suffix := any character combination including whitespace
  • integer := #* 0* 0
  • fraction := 0* #*

0* and #* stand for multiple 0 or # respectively. 0 and # perform similar functions but 0 ensures that length of all numbers is same i.e. if a digit is missing it is replaced by 0. For example 54 will be formatted to 0054 with pattern '0000' and it will be formatted to 54 with pattern '####'.

The following placeholders can be used within the pattern parameter:

  • . placeholder for decimal separator.
  • , placeholder for grouping separator.
  • E separates mantissa and exponent for exponential formats.
  • - default negative prefix.
  • % multiply by 100 and show as percentage.
  • ' used to quote special characters in a prefix or suffix.

The locale parameter is ignored when the format type parameter is set to 'pattern'. In other cases it plays its role e.g. if the format type parameter is set to 'currency' then the locale parameter specifies the notation for that currency (i.e. dollar, euro etc).

Input

  • example set input (Data table)

    This input port expects an ExampleSet. It is the output of the Generate Data operator in the attached Example Process. The output of other operators can also be used as input. The ExampleSet should have at least one numerical attribute because if there is no such attribute, the use of this operator does not make sense.

Output

  • example set output (Data table)

    The selected numerical attributes are reformatted and converted to nominal and the resultant ExampleSet is delivered through this port.

  • original (Data table)

    The ExampleSet that was given as input is passed without changing to the output through this port. This is usually used to reuse the same ExampleSet in further operators or to view the ExampleSet in the Results Workspace.

Parameters

  • attribute filter typeThis parameter allows you to select the attribute selection filter; the method you want to use for selecting the required attributes. It has the following options:
    • all: This option simply selects all the attributes of the ExampleSet. This is the default option.
    • single: This option allows selection of a single attribute. When this option is selected another parameter (attribute) becomes visible in the Parameters panel. (Since RapidMiner 6.0.4 the Operator will fail if a selected Attribute is not in the ExampleSet)
    • subset: This option allows selection of multiple attributes through a list. All attributes of the ExampleSet are present in the list; required attributes can be easily selected. This option will not work if the meta data is not known. When this option is selected another parameter becomes visible in the Parameters panel. (Since RapidMiner 6.0.4 the Operator will fail if a selected Attribute is not in the ExampleSet)
    • regular expression: This option allows you to specify a regular expression for attribute selection. When this option is selected some other parameters (regular expression, use except expression) become visible in the Parameters panel.
    • value type: This option allows selection of all the attributes of a particular type. It should be noted that types are hierarchical. For example real and integer types both belong to the numeric type. Users should have a basic understanding of type hierarchy when selecting attributes through this option. When this option is selected some other parameters (value type, use value type exception) become visible in the Parameters panel.
    • block type: This option is similar in working to the value type option. This option allows selection of all the attributes of a particular block type. When this option is selected some other parameters (block type, use block type exception) become visible in the Parameters panel.
    • no missing values: This option simply selects all the attributes of the ExampleSet which don't contain a missing value in any example. Attributes that have even a single missing value are removed.
    • numeric value filter: When this option is selected another parameter (numeric condition) becomes visible in the Parameters panel. All numeric attributes whose examples all satisfy the mentioned numeric condition are selected. Please note that all nominal attributes are also selected irrespective of the given numerical condition.
  • attributeThe desired attribute can be selected from this option. The attribute name can be selected from the dropdown box of attribute parameter if the meta data is known.
  • attributesThe required attributes can be selected from this option. This opens a new window with two lists. All attributes are present in the left list and can be shifted to the right list which is the list of selected attributes on which the conversion from nominal to numeric will take place; all other attributes will remain unchanged.
  • regular expressionThe attributes whose name matches this expression will be selected. Regular expression is a very powerful tool but needs a detailed explanation to beginners. It is always good to specify the regular expression through the edit and preview regular expression menu. This menu gives a good idea of regular expressions. This menu also allows you to try different expressions and preview the results simultaneously. This will enhance your concept of regular expressions.
  • use except expressionIf enabled, an exception to the selected type can be specified. When this option is selected another parameter (except value type) becomes visible in the Parameters panel.
  • except regular expressionThis option allows you to specify a regular expression. Attributes matching this expression will be filtered out even if they match the first expression (expression that was specified in the regular expression parameter).
  • value typeThe type of attributes to be selected can be chosen from a dropdown list. One of the following types can be chosen: nominal, text, binominal, polynominal, file_path.
  • use value type exception If enabled, an exception to the selected type can be specified. When this option is selected another parameter (except value type) becomes visible in the Parameters panel.
  • except value typeThe attributes matching this type will be removed from the final output even if they matched the previously mentioned type i.e. value type parameter's value. One of the following types can be selected here: nominal, text, binominal, polynominal, file_path.
  • block typeThe block type of attributes to be selected can be chosen from a dropdown list. The only possible value here is 'single_value'
  • use block type exceptionIf enabled, an exception to the selected block type can be specified. When this option is selected another parameter (except block type) becomes visible in the Parameters panel.
  • except block typeThe attributes matching this block type will be removed from the final output even if they matched the previously mentioned block type.
  • numeric conditionThe numeric condition for testing examples of numeric attributes is specified here. For example the numeric condition '> 6' will keep all nominal attributes and all numeric attributes having a value of greater than 6 in every example. A combination of conditions is possible: '> 6 && < 11' or '<= 5 || < 0'. But && and || cannot be used together in one numeric condition. Conditions like '(> 0 && < 2) || (>10 && < 12)' are not allowed because they use both && and ||. Use a blank space after '>', '=' and '<' e.g. '<5' will not work, so use '< 5' instead.
  • include special attributesThe special attributes are attributes with special roles which identify the examples. In contrast, regular attributes simply describe the examples. Special attributes are: id, label, prediction, cluster, weight and batch.
  • invert selectionIf this parameter is set to true, it acts as a NOT gate, it reverses the selection. In that case all the selected attributes are unselected and previously unselected attributes are selected. For example if attribute 'att1' is selected and attribute 'att2' is unselected prior to checking of this parameter. After checking of this parameter 'att1' will be unselected and 'att2' will be selected.
  • format typeThis parameter specifies the type of formatting to perform on the selected numerical attributes.
  • patternThis parameter is only available when the format type parameter is set to 'pattern'. This parameter specifies the pattern for formatting the numbers. Various structures and replacement patterns for this parameter have been discussed in the description of this operator.
  • localeThis is an expert parameter. A long list of locales is provided; users can select any of them.
  • use groupingThis parameter indicates if a grouping character should be used for larger numbers.

Tutorial Processes

Changing numeric values to currency format

This process starts with the Generate Data operator which generates a random ExampleSet with a numeric attribute named 'att1'. A breakpoint is inserted here so that you can have a look at the ExampleSet. The Format Numbers operator is applied on it to change the format of this attribute to a currency format. The attribute filter type parameter is set to 'single' and the attribute parameter is set to 'att1' to select the required attribute. The format type parameter is set to 'currency'. Run the process and switch to the Results Workspace. You can see that the 'att1' attribute has been changed from numeric to nominal type and its values have a '$' sign in the beginning because they have been converted to a currency format. The locale parameter specifies the required currency. In this process the locale parameter was set to 'English (United States)' therefore the numeric values were converted to the currency of United States (i.e. dollar).