24 Transforming the Data
Understand how to transform data for building a model or for scoring.
24.1 About Transformations
Understand how you can transform data by using Automatic Data Preparation (ADP) and embedded data transformation.
A transformation is a SQL expression that modifies the data in one or more columns. Data must typically undergo certain transformations before it can be used to build a model. Many data mining algorithms have specific transformation requirements. Before data can be scored, it must be transformed in the same way that the training data was transformed.
Oracle Data Mining supports Automatic Data Preparation (ADP), which automatically implements the transformations required by the algorithm. The transformations are embedded in the model and automatically executed whenever the model is applied.
If additional transformations are required, you can specify them as SQL expressions and supply them as input when you create the model. These transformations are embedded in the model just as they are with ADP.
With automatic and embedded data transformation, most of the work of data preparation is handled for you. You can create a model and score multiple data sets in just a few steps:
-
Identify the columns to include in the case table.
-
Create nested columns if you want to include transactional data.
-
Write SQL expressions for any transformations not handled by ADP.
-
Create the model, supplying the SQL expressions (if specified) and identifying any columns that contain text data.
-
Ensure that some or all of the columns in the scoring data have the same name and type as the columns used to train the model.
Related Topics
24.2 Preparing the Case Table
Understand why you have to prepare a case table.
The first step in preparing data for mining is the creation of a case table. If all the data resides in a single table and all the information for each case (record) is included in a single row (single-record case), this process is already taken care of. If the data resides in several tables, creating the data source involves the creation of a view. For the sake of simplicity, the term "case table" is used here to refer to either a table or a view.
Related Topics
24.2.1 Creating Nested Columns
Learn when to create nested columns.
When the data source includes transactional data (multi-record case), the transactions must be aggregated to the case level in nested columns. In transactional data, the information for each case is contained in multiple rows. An example is sales data in a star schema when mining at the product level. Sales is stored in many rows for a single product (the case) since the product is sold in many stores to many customers over a period of time.
See Also:
Using Nested Data for information about converting transactional data to nested columns
24.2.2 Converting Column Data Types
You must convert the data type of a column if its type causes Oracle Data Mining to interpret it incorrectly. For example, zip codes identify different postal zones; they do not imply order. If the zip codes are stored in a numeric column, they are interpreted as a numeric attribute. You must convert the data type so that the column data can be used as a categorical attribute by the model. You can do this using the TO_CHAR
function to convert the digits 1-9 and the LPAD
function to retain the leading 0, if there is one.
LPAD(TO_CHAR(ZIPCODE),5,'0')
24.2.3 Text Transformation
You can use Oracle Data Mining to mine text. Columns of text in the case table can be mined once they have undergone the proper transformation.
The text column must be in a table, not a view. The transformation process uses several features of Oracle Text; it treats the text in each row of the table as a separate document. Each document is transformed to a set of text tokens known as terms, which have a numeric value and a text label. The text column is transformed to a nested column of DM_NESTED_NUMERICALS
.
24.2.4 About Business and Domain-Sensitive Transformations
Understand why you need to transform data according to business problems.
Some transformations are dictated by the definition of the business problem. For example, you want to build a model to predict high-revenue customers. Since your revenue data for current customers is in dollars you need to define what "high-revenue" means. Using some formula that you have developed from past experience, you can recode the revenue attribute into ranges Low, Medium, and High before building the model.
Another common business transformation is the conversion of date information into elapsed time. For example, date of birth can be converted to age.
Domain knowledge can be very important in deciding how to prepare the data. For example, some algorithms produce unreliable results if the data contains values that fall far outside of the normal range. In some cases, these values represent errors or abnormalities. In others, they provide meaningful information.
Related Topics
24.3 Understanding Automatic Data Preparation
Understand data transformation using Automatic Data Preparation (ADP).
Most algorithms require some form of data transformation. During the model build process, Oracle Data Mining can automatically perform the transformations required by the algorithm. You can choose to supplement the automatic transformations with additional transformations of your own, or you can choose to manage all the transformations yourself.
In calculating automatic transformations, Oracle Data Mining uses heuristics that address the common requirements of a given algorithm. This process results in reasonable model quality in most cases.
Binning, normalization, and outlier treatment are transformations that are commonly needed by data mining algorithms.
Related Topics
24.3.1 Binning
Binning, also called discretization, is a technique for reducing the cardinality of continuous and discrete data. Binning groups related values together in bins to reduce the number of distinct values.
Binning can improve resource utilization and model build response time dramatically without significant loss in model quality. Binning can improve model quality by strengthening the relationship between attributes.
Supervised binning is a form of intelligent binning in which important characteristics of the data are used to determine the bin boundaries. In supervised binning, the bin boundaries are identified by a single-predictor decision tree that takes into account the joint distribution with the target. Supervised binning can be used for both numerical and categorical attributes.
24.3.3 Outlier Treatment
A value is considered an outlier if it deviates significantly from most other values in the column. The presence of outliers can have a skewing effect on the data and can interfere with the effectiveness of transformations such as normalization or binning.
Outlier treatment methods such as trimming or clipping can be implemented to minimize the effect of outliers.
Outliers represent problematic data, for example, a bad reading due to the abnormal condition of an instrument. However, in some cases, especially in the business arena, outliers are perfectly valid. For example, in census data, the earnings for some of the richest individuals can vary significantly from the general population. Do not treat this information as an outlier, since it is an important part of the data. You need domain knowledge to determine outlier handling.
24.3.4 How ADP Transforms the Data
The following table shows how ADP prepares the data for each algorithm.
Table 24-1 Oracle Data Mining Algorithms With ADP
Algorithm | Mining Function | Treatment by ADP |
---|---|---|
Association Rules |
ADP has no effect on association rules. |
|
Classification |
ADP has no effect on Decision Tree. Data preparation is handled by the algorithm. |
|
Clustering |
Single-column (not nested) numerical columns that are modeled with Gaussian distributions are normalized with outlier-sensitive normalization. ADP has no effect on the other types of columns. |
|
Classification and Regression |
Numerical attributes are normalized with outlier-sensitive normalization. |
|
Clustering |
Numerical attributes are normalized with outlier-sensitive normalization. |
|
Attribute Importance |
All attributes are binned with supervised binning. |
|
Classification |
All attributes are binned with supervised binning. |
|
Feature Extraction |
Numerical attributes are normalized with outlier-sensitive normalization. |
|
Clustering |
Numerical attributes are binned with a specialized form of equi-width binning, which computes the number of bins per attribute automatically. Numerical columns with all nulls or a single value are removed. |
|
Feature Extraction |
Numerical attributes are normalized with outlier-sensitive normalization. |
|
Classification, Anomaly Detection, and Regression |
Numerical attributes are normalized with outlier-sensitive normalization. |
See Also:
-
Part III of Oracle Data Mining Concepts for more information about algorithm-specific data preparation
24.4 Embedding Transformations in a Model
You can specify your own transformations and embed them in a model by creating a transformation list and passing it to DBMS_DATA_MINING.CREATE_MODEL
.
PROCEDURE create_model(
model_name IN VARCHAR2,
mining_function IN VARCHAR2,
data_table_name IN VARCHAR2,
case_id_column_name IN VARCHAR2,
target_column_name IN VARCHAR2 DEFAULT NULL,
settings_table_name IN VARCHAR2 DEFAULT NULL,
data_schema_name IN VARCHAR2 DEFAULT NULL,
settings_schema_name IN VARCHAR2 DEFAULT NULL,
xform_list IN TRANSFORM_LIST DEFAULT NULL
);
24.4.1 Specifying Transformation Instructions for an Attribute
Learn what is a transformation instruction for an attribute and learn about the fields in a transformation record.
A transformation list is defined as a table of transformation records. Each record (transform_rec
) specifies the transformation instructions for an attribute.
TYPE transform_rec IS RECORD ( attribute_name VARCHAR2(30), attribute_subname VARCHAR2(4000), expression EXPRESSION_REC, reverse_expression EXPRESSION_REC, attribute_spec VARCHAR2(4000));
The fields in a transformation record are described in this table.
Table 24-2 Fields in a Transformation Record for an Attribute
Field | Description |
---|---|
|
These fields identify the attribute, as described in "Scoping of Model Attribute Name" |
|
A SQL expression for transforming the attribute. For example, this expression transforms the age attribute into two categories: child and adult:[0,19) for 'child' and [19,) for adult CASE WHEN age < 19 THEN 'child' ELSE 'adult' Expression and reverse expressions are stored in |
|
A SQL expression for reversing the transformation. For example, this expression reverses the transformation of the age attribute: DECODE(age,'child','(-Inf,19)','[19,Inf)') |
|
Specifies special treatment for the attribute. The
See Example 24-1 and Example 24-2. |
Related Topics
24.4.1.1 Expression Records
The transformation expressions in a transformation record are expression_rec
objects.
TYPE expression_rec IS RECORD ( lstmt DBMS_SQL.VARCHAR2A, lb BINARY_INTEGER DEFAULT 1, ub BINARY_INTEGER DEFAULT 0); TYPE varchar2a IS TABLE OF VARCHAR2(32767) INDEX BY BINARY_INTEGER;
The lstmt
field stores a VARCHAR2A
, which allows transformation expressions to be very long, as they can be broken up across multiple rows of VARCHAR2
. Use the DBMS_DATA_MINING_TRANSFORM.SET_EXPRESSION
procedure to create an expression_rec
.
24.4.1.2 Attribute Specifications
Learn how to define the characteristics specific to an attribute through attribute specification.
The attribute specification in a transformation record defines characteristics that are specific to this attribute. If not null, the attribute specification can include values FORCE_IN
, NOPREP
, or TEXT
, as described in Table 24-2.
Example 24-1 An Attribute Specification with Multiple Keywords
If more than one attribute specification keyword is applicable, you can provide them in a comma-delimited list. The following expression is the specification for an attribute in a GLM model. Assuming that the ftr_selection_enable
setting is enabled, this expression forces the attribute to be included in the model. If ADP is on, automatic transformation of the attribute is not performed.
"FORCE_IN,NOPREP"
Example 24-2 A Text Attribute Specification
For text attributes, you can optionally specify subsettings POLICY_NAME
, TOKEN_TYPE
, and MAX_FEATURES
. The subsettings provide configuration information that is specific to text transformation. In this example, the transformation instructions for the text content are defined in a text policy named my_policy
with token type is THEME
. The maximum number of extracted features is 3000.
"TEXT(POLICY_NAME:my_policy)(TOKEN_TYPE:THEME)(MAX_FEATURES:3000)"
Related Topics
24.4.2 Building a Transformation List
A transformation list is a collection of transformation records. When a new transformation record is added, it is appended to the top of the transformation list. You can use any of the following methods to build a transformation list:
-
The
SET_TRANFORM
procedure inDBMS_DATA_MINING_TRANSFORM
-
The
STACK
interface inDBMS_DATA_MINING_TRANSFORM
-
The
GET_MODEL_TRANSFORMATIONS
andGET_TRANSFORM_LIST
functions inDBMS_DATA_MINING
24.4.2.1 SET_TRANSFORM
The SET_TRANSFORM
procedure adds a single transformation record to a transformation list.
DBMS_DATA_MINING_TRANSFORM.SET_TRANSFORM ( xform_list IN OUT NOCOPY TRANSFORM_LIST, attribute_name VARCHAR2, attribute_subname VARCHAR2, expression VARCHAR2, reverse_expression VARCHAR2, attribute_spec VARCHAR2 DEFAULT NULL);
SQL expressions that you specify with SET_TRANSFORM
must fit within a VARCHAR2
. To specify a longer expression, you can use the SET_EXPRESSION
procedure, which builds an expression by appending rows to a VARCHAR2
array.
24.4.2.2 The STACK Interface
The STACK
interface creates transformation records from a table of transformation instructions and adds them to a transformation list.
The STACK
interface specifies that all or some of the attributes of a given type must be transformed in the same way. For example, STACK_BIN_CAT
appends binning instructions for categorical attributes to a transformation list. The STACK
interface consists of three steps:
-
A
CREATE
procedure creates a transformation definition table. For example,CREATE_BIN_CAT
creates a table to hold categorical binning instructions. The table has columns for storing the name of the attribute, the value of the attribute, and the bin assignment for the value. -
An
INSERT
procedure computes the bin boundaries for one or more attributes and populates the definition table. For example,INSERT_BIN_CAT_FREQ
performs frequency-based binning on some or all of the categorical attributes in the data source and populates a table created byCREATE_BIN_CAT
. -
A
STACK
procedure creates transformation records from the information in the definition table and appends the transformation records to a transformation list. For example, STACK_BIN_CAT creates transformation records for the information stored in a categorical binning definition table and appends the transformation records to a transformation list.
24.4.2.3 GET_MODEL_TRANSFORMATIONS and GET_TRANSFORM_LIST
Use the functions to create a new transformation list.
These two functions can be used to create a new transformation list from the transformations embedded in an existing model.
The GET_MODEL_TRANSFORMATIONS
function returns a list of embedded transformations.
DBMS_DATA_MINING.GET_MODEL_TRANSFORMATIONS ( model_name IN VARCHAR2) RETURN DM_TRANSFORMS PIPELINED;
GET_MODEL_TRANSFORMATIONS
returns a table of dm_transform
objects. Each dm_transform
has these fields
attribute_name VARCHAR2(4000) attribute_subname VARCHAR2(4000) expression CLOB reverse_expression CLOB
The components of a transformation list are transform_rec
, not dm_transform
. The fields of a transform_rec
are described in Table 24-2. You can call GET_MODEL_TRANSFORMATIONS
to convert a list of dm_transform
objects to transform_rec
objects and append each transform_rec
to a transformation list.
DBMS_DATA_MINING.GET_TRANSFORM_LIST ( xform_list OUT NOCOPY TRANSFORM_LIST, model_xforms IN DM_TRANSFORMS);
See Also:
"DBMS_DATA_MINING_TRANSFORM Operational Notes", "SET_TRANSFORM Procedure", "CREATE_MODEL Procedure", and "GET_MODEL_TRANSFORMATIONS Function" in Oracle Database PL/SQL Packages and Types Reference
24.4.3 Transformation Lists and Automatic Data Preparation
If you enable ADP and you specify a transformation list, the transformation list is embedded with the automatic, system-generated transformations. The transformation list is executed before the automatic transformations.
If you enable ADP and do not specify a transformation list, only the automatic transformations are embedded in the model.
If ADP is disabled (the default) and you specify a transformation list, your custom transformations are embedded in the model. No automatic transformations are performed.
If ADP is disabled (the default) and you do not specify a transformation list, no transformations is embedded in the model. You have to transform the training, test, and scoring data sets yourself if necessary. You must take care to apply the same transformations to each data set.
24.4.4 Oracle Data Mining Transformation Routines
Learn about transformation routines.
Oracle Data Mining provides routines that implement various transformation techniques in the DBMS_DATA_MINING_TRANSFORM
package.
Related Topics
24.4.4.1 Binning Routines
Explains Binning techniques in Oracle Data Mining.
A number of factors go into deciding a binning strategy. Having fewer values typically leads to a more compact model and one that builds faster, but it can also lead to some loss in accuracy.
Model quality can improve significantly with well-chosen bin boundaries. For example, an appropriate way to bin ages is to separate them into groups of interest, such as children 0-13, teenagers 13-19, youth 19-24, working adults 24-35, and so on.
The following table lists the binning techniques provided by Oracle Data Mining:
Table 24-3 Binning Methods in DBMS_DATA_MINING_TRANSFORM
Related Topics
24.4.4.2 Normalization Routines
Learn about Normalization routines in Oracle Data Mining.
Most normalization methods map the range of a single attribute to another range, typically 0 to 1 or -1 to +1.
Normalization is very sensitive to outliers. Without outlier treatment, most values are mapped to a tiny range, resulting in a significant loss of information.
Table 24-4 Normalization Methods in DBMS_DATA_MINING_TRANSFORM
Transformation | Description |
---|---|
This technique computes the normalization of an attribute using the minimum and maximum values. The shift is the minimum value, and the scale is the difference between the maximum and minimum values. |
|
This normalization technique also uses the minimum and maximum values. For scale normalization, shift = 0, and scale = max{abs(max), abs(min)}. |
|
This technique computes the normalization of an attribute using the mean and the standard deviation. Shift is the mean, and scale is the standard deviation. |
Related Topics
24.4.4.3 Routines for Outlier Treatment
Outliers are extreme values, typically several standard deviations from the mean. To minimize the effect of outliers, you can Winsorize or trim the data.
Winsorizing involves setting the tail values of an attribute to some specified value. For example, for a 90% Winsorization, the bottom 5% of values are set equal to the minimum value in the 5th percentile, while the upper 5% of values are set equal to the maximum value in the 95th percentile.
Trimming sets the tail values to NULL. The algorithm treats them as missing values.
Outliers affect the different algorithms in different ways. In general, outliers cause distortion with equi-width binning and min-max normalization.
Table 24-5 Outlier Treatment Methods in DBMS_DATA_MINING_TRANSFORM
Transformation | Description |
---|---|
This technique trims the outliers in numeric columns by sorting the non-null values, computing the tail values based on some fraction, and replacing the tail values with nulls. |
|
This technique trims the outliers in numeric columns by sorting the non-null values, computing the tail values based on some fraction, and replacing the tail values with some specified value. |
24.5 Understanding Reverse Transformations
Understand why you need reverse transformations.
Reverse transformations ensure that information returned by the model is expressed in a format that is similar to or the same as the format of the data that was used to train the model. Internal transformation are reversed in the model details and in the results of scoring.
Some of the attributes used by the model correspond to columns in the build data. However, because of logic specific to the algorithm, nested data, and transformations, some attributes donot correspond to columns.
For example, a nested column in the training data is not interpreted as an attribute by the model. During the model build, Oracle Data Mining explodes nested columns, and each row (an attribute name/value pair) becomes an attribute.
Some algorithms, for example Support Vector Machines (SVM) and Generalized Linear Models (GLM), only operate on numeric attributes. Any non-numeric column in the build data is exploded into binary attributes, one for each distinct value in the column (SVM). GLM does not generate a new attribute for the most frequent value in the original column. These binary attributes are set to one only if the column value for the case is equal to the value associated with the binary attribute.
Algorithms that generate coefficients present challenges in regards to interpretability of results. Examples are SVM and Non-Negative Matrix Factorization (NMF). These algorithms produce coefficients that are used in combination with the transformed attributes. The coefficients are relevant to the data on the transformed scale, not the original data scale.
For all these reasons, the attributes listed in the model details donot resemble the columns of data used to train the model. However, attributes that undergo embedded transformations, whether initiated by Automatic Data Preparation (ADP) or by a user-specified transformation list, appear in the model details in their pre-transformed state, as close as possible to the original column values. Although the attributes are transformed when they are used by the model, they are visible in the model details in a form that can be interpreted by a user.