  Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second Edition by Galit Shmueli, Nitin R. Patel and Peter C. Bruce John Wiley & Sons (US). (c) 2010. Copying Prohibited.    Reprinted for Ana Maria TUTA OSMAN, SAP ANA.MARIA.TUTA.OSMAN@SAP.COM Reprinted with permission as a subscription benefit of Skillport, http://skillport.books24x7.com/  All rights reserved. Reproduction and/or distribution in whole or in part in electronic,paper or other forms without written permission is prohibited.   Page 2 / 15

Chapter 4: Dimension Reduction In this chapter we describe the important step of dimension reduction. The dimension of a dataset, which is the number of variables, must be reduced for the data mining algorithms to operate efficiently. We present and discuss several dimension reduction approaches: (1) Incorporating domain knowledge to remove or combine categories, (2) using data summaries to detect information overlap between variables (and remove or combine redundant variables or categories), (3) using data conversion techniques such as converting categorical variables into numerical variables, and (4) employing automated reduction techniques, such as principal components analysis (PCA), where a new set of variables (which are weighted averages of the original variables) is created. These new variables are uncorrelated and a small subset of them usually contains most of their combined information (hence, we can reduce dimension by using only a subset of the new variables). Finally, we mention data mining methods such as regression models and regression and classification trees, which can be used for removing redundant variables and for combining "similar" categories of categorical variables. 4.1 Introduction In data mining one often encounters situations where there are a large number of variables in the database. In such situations it is very likely that subsets of variables are highly correlated with each other. Included in a classification or prediction model, highly correlated variables, or variables that are unrelated to the outcome of interest, can lead to overfitting, and accuracy and reliability can suffer. Large numbers of variables also pose computational problems for some models (aside from questions of correlation). In model deployment, superfluous variables can increase costs due to the collection and processing of these variables. The dimensionality of a model is the number of independent or input variables used by the model. One of the key steps in data mining, therefore, is finding ways to reduce dimensionality without sacrificing accuracy. In the artificial intelligence literature, dimension reduction is often referred to as factor selection or feature extraction. 4.2 Practical Considerations Although data mining prefers automated methods over domain knowledge, it is important at the first step of data exploration to make sure that the variables measured are reasonable for the task at hand. The integration of expert knowledge through a discussion with the data provider (or user) will probably lead to better results. Practical considerations include: Which variables are most important for the task at hand, and which are most likely to be useless? Which variables are likely to contain much error? Which variables will be available for measurement (and what will it cost to measure them) in the future if the analysis is repeated? Which variables can actually be measured before the outcome occurs? (For example, if we want to predict the closing price of an ongoing online auction, we cannot use the number of bids as a predictor because this will not be known until the auction closes.) Example 1: House Prices in Boston We return to the Boston housing example introduced in Chapter 2. For each neighborhood, a number of variables are given, such as the crime rate, the student/teacher ratio, and the median value of a housing unit in the neighborhood. A description of all 14 variables is given in Table 4.1. The first 10 records of the data are shown in Figure 4.1. The first row in this figure represents the first neighborhood, which had an average per capita crime rate of 0.006, 18% of the residential land zoned for lots over 25, 000 ft2, 2.31% of the land devoted to nonretail business, no border on the Charles River, and so on. Table 4.1: DESCRIPTION OF VARIABLES IN THE BOSTON HOUSING DATASET CRIM Crime rate ZN Percentage of residential land zoned for lots over 25, 000 ft2  INDUS Percentage of land occupied by nonretail business CHAS Charles River dummy variable (= 1 if tract bounds river; =0 otherwise) NOX Nitric oxide concentration (parts per 10 million) RM Average number of rooms per dwelling AGE Percentage of owner-occupied units built prior to 1940 DIS Weighted distances to five Boston employment centers Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 3 / 15

  FIGURE 4.1: FIRST NINE RECORDS IN THE BOSTON HOUSING DATASET  4.3 Data Summaries As we have seen in Chapter 3 on data visualization, an important initial step of data exploration is getting familiar with the data and their characteristics through summaries and graphs. The importance of this step cannot be overstated. The better you understand the data, the better the results from the modeling or mining process will be. Numerical summaries and graphs of the data are very helpful for data reduction. The information that they convey can assist in combining categories of a categorical variable, in choosing variables to remove, in assessing the level of information overlap between variables, and more. Before discussing such strategies for reducing the dimension of a data set, let us consider useful summaries and tools. Summary Statistics Excel has several functions and facilities that assist in summarizing data. The functions average, stdev, min, max, median, and count are very helpful for learning about the characteristics of each variable. First, they give us information about the scale and type of values that the variable takes. The min and max functions can be used to detect extreme values that might be errors. The average and median give a sense of the central values of that variable, and a large deviation between the two also indicates skew. The standard deviation gives a sense of how dispersed the data are (relative to the mean). Other functions, such as countblank, which gives the number of empty cells, can tell us about missing values. It is also possible to use Excel's Descriptive Statistics facility in the Data > Data Analysis menu (in Excel 2003: Tools > Data Analysis). This will generate a set of 13 summary statistics for each of the variables. Figure 4.2 shows six summary statistics for the Boston housing example. We see immediately that the different variables have very different ranges of values. We will see soon how variation in scale across variables can distort analyses ifnot treated properly. Another observation that can be made is that the average of the first variable, CRIM (as well as several others), is much larger than the median, indicating right skew. None of the variables have empty cells. There also do not appear to be indications of extreme values that might result from typing errors. RAD Index of accessibility to radial highways TAX Full-value property tax rate per $10, 000 PTRATIO Pupil/teacher ratio by town B 1000(Bk minus 0.63)2, where Bk is the proportion of blacks by town LSTAT % Lower status of the population MEDV Median value of owner-occupied homes in $1000s Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 4 / 15

  FIGURE 4.2: SUMMARY STATISTICS FOR THE BOSTON HOUSING DATA  Next, we summarize relationships between two or more variables. For numerical variables, we can compute pairwise correlations (using the Excel function correl). We can also obtain a complete matrix of correlations between each pair of variables in the data using Excel's Correlation facility in the Data > Data Analysis menu (in Excel 2003, Tools > Data Analysis). Figure 4.3 shows the correlation matrix for a subset of the Boston housing variables. We see that most are low and that many are negative. Recall also the visual display of a correlation matrix via a heatmap (see Figure 3.3 for the heatmap corresponding to this correlation table). We will return to the importance of the correlation matrix soon, in the context of correlation analysis.   FIGURE 4.3: CORRELATION TABLE FOR BOSTON HOUSING DATA, GENERATED USING EXCEL'S DATA ANALYSIS MENU  Pivot Tables Another very useful tool is Excel's pivot tables, inthe Insert > Data menu (in Excel 2003, in the Data menu). These are interactive tables that can combine information from multiple variables and compute a range of summary statistics (count, average, percentage, etc.). A simple example is the average MEDV for neighborhoods that bound the Charles River versus those that do not. First, we get a count of neighborhoods bordering the river. The Excel pivot table in Figure 4.4 (top panel) was obtained by selecting CHAS as a "row labels" field and MEDV or any other variable as a "values" field, using the "count" summary. It appears that the majority of neighborhoods (471 of 506) do not bound the river. By double-clicking on a certain cell, the complete data for records in that cell are shown on a new worksheet. For instance, double-clicking on the cell containing 471 will display the complete records of neighborhoods that do not bound the river. Pivot tables can be used for multiple variables. For categorical variables we obtain a breakdown of the records by the combination of categories. For instance, the bottom panel of Figure 4.4 shows the average MEDV by CHAS (column) and RM (row). Note that the numerical variable RM (the average number of rooms per dwelling in the neighborhood) is grouped into bins of 3-4, 5-6, and so on. Note also the empty cells, denoting that there are no neighborhoods in the dataset with those combinations (e.g., bounding the river and having on average three or four rooms). There are many more possibilities and options for using Excel's pivot tables. We leave it to the reader to explore these using Excel's documentation. Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 5 / 15

  FIGURE 4.4: PIVOT TABLES FOR THE BOSTON HOUSING DATA  In classification tasks, where the goal is to find predictor variables that do a good job of distinguishing between two classes, a good exploratory step is to produce summaries for each class. This can assist in detecting useful predictors that display some separation between the two classes. Data summaries are useful for almost any data mining task and are therefore an important preliminary step for cleaning and understanding the data before carrying out further analyses. 4.4 Correlation Analysis In datasets with a large number of variables (which are likely to serve as predictors), there is usually much overlap in the information covered by the set of variables. One simple way to find redundancies is to look at a correlation matrix. This shows all the pairwise correlations between variables. Pairs that have a very strong (positive or negative) correlation contain a lot of overlap in information and are good candidates for data reduction by removing one of the variables. Removing variables that are strongly correlated to others is useful for avoiding multicollinearity problems that can arise in various models. (Multicollinearity is the presence of two or more predictors sharing the same linear relationship with the outcome variable.) Correlation analysis is also a good method for detecting duplications of variables in the data. Sometimes, the same variable appears accidentally more than once in the dataset (under a different name) because the dataset was merged from multiple sources, the same phenomenon is measured in different units, and so on. Using correlation table heatmaps, as shown in Chapter 3, can make the task of identifying strong correlations easier. 4.5 Reducing the Number of Categories in Categorical Variables When a categorical variable has many categories, and this variable is destined to be a predictor, many data mining methods will require converting it into many dummy variables. In particular, a variable with m categories will be transformed into m — 1 dummy variables. This means that even if we have very few original categorical variables, they can greatly inflate the dimension of the dataset. One way to handle this is to reduce the number of categories by combining close or similar categories. To combine categories requires incorporating expert knowledge and common sense. Pivot tables are useful for this task: We can examine the sizes of the various categories and how the response behaves at each category. Generally, categories that contain very few observations are good candidates for combining with other categories. Use only the categories that are most relevant to the analysis, and label the rest as "other." In classification tasks (with a categorical output), a pivot table broken down by the output classes can help identify categories that do not separate the classes. Those categories too are candidates for inclusion in the "other" category. An example is shown in Figure 4.5, where the distribution of output variable CAT.MEDV is broken down by ZN (treated here as a categorical variable). We can see that the distribution of CAT.MEDV is identical for ZN=17.5, 90, 95, and 100 (where all neighborhoods have CAT.MEDV=1). These four categories can then be combined into a single category. Similarly categories ZN=12.5, 25, 28, 30, and 70 can be combined. Further combination is also possible based on similar bars. Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 6 / 15

  FIGURE 4.5: DISTRIBUTION OF CAT.MEDV (BLACK DENOTES CAT.MEDV=O) BY ZN. SIMILAR BARS INDICATE LOW SEPARATION BETWEEN CLASSES AND CAN BE COMBINED  In a time series context where we might have a categorical variable denoting season (such as month, or hour of day) that will serve as a predictor, reducing categories can be done by examining the time series plot and identifying similar periods. For example, the time plot in Figure 4.6 shows the quarterly revenues of Toys "R" Us between 1992 and 1995. Only quarter 4 periods appear different, and therefore we can combine quarters 1-3 into a single category.   FIGURE 4.6: QUARTERLY REVENUES OF TOYS "R" US, 1992-1995  4.6 Converting a Categorical Variable to a Numerical Variable Sometimes the categories in a categorical variable represent intervals. Common examples are age group or income group. If the interval values are known (e.g., category 2 is the age interval 20-30), we can replace the categorical value ("2" in the example) with the midinterval value (here "25"). The result will be a numerical variable that no longer requires multiple dummy variables. 4.7 Principal Components Analysis Principal components analysis (PCA) is a useful procedure for reducing the number of predictors in the model by analyzing the input variables. It is especially valuable when we have subsets of measurements that are highly correlated. In that case it provides a few variables (often as few as three) that are weighted linear combinations of the original variables that retain the explanatory power of the full original set. PCA is intended for use with quantitative variables. For categorical variables, other methods, such as correspondence analysis, are more suitable. Example 2: Breakfast Cereals Data were collected on the nutritional information and consumer rating of 77 breakfast cereals.[1] For each cereal the data include 13 numerical variables, and we are interested in reducing this dimension. For each cereal the information is based on a bowl of cereal rather than a serving size because most people simply fill a cereal bowl (resulting in constant volume, Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 7 / 15

but not weight). A snapshot of these data is given in Figure 4.7, and the description of the different variables is given in Table 4.2.   FIGURE 4.7: SAMPLE FROM THE 77 BREAKFAST CEREALS DATASET  We focus first on two variables: calories and consumer rating. These are given in Table 4.3. The average calories across the 75 cereals is 106.88 and the average consumer rating is 42.67. The estimated covariance matrix between the two variables is   Table 4.2: DESCRIPTION OF THE VARIABLES IN THE BREAKFAST CEREAL DATASET Variable Description mfr Manufacturer of cereal (American Home Food Products, General Mills, Kellogg, etc.) type Cold or hot calories Calories per serving protein Grams of protein fat Grams of fat sodium Milligrams of sodium fiber Grams of dietary fiber carbo Grams of complex carbohydrates sugars Grams of sugars potass Milligrams of potassium vitamins Vitamins and minerals: 0, 25, or 100,  indicating the typical percentage of FDA recommended shelf Display shelf (1, 2, or 3, counting from the floor) weight Weight in ounces of one serving cups Number of cups in one serving rating Rating of the cereal calculated by Consumer Reports  Table 4.3: CEREAL CALORIES AND RATINGS Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 8 / 15

Cereal Calories Rating Cereal Calories Rating 100% Bran 70 68.40297 Just Right Crunchy Nuggets 110 36.52368 100% Natural Bran 120 33.98368    All-Bran 70 59.42551 Just Right Fruit & Nut 140 36.471512 All-Bran with Extra Fiber 50 93.70491 Kix 110 39.241114    Life 100 45.328074 Almond Delight 110 34.38484 Lucky Charms 110 26.734515 Apple Cinnamon Cheerios 110 29.50954 Maypo 100 54.850917    Muesli Raisins, Dates & Almonds 150 37.136863 Apple Jacks 110 33.17409    Basic 4 130 37.03856 Muesli Raisins, Peaches & Pecans 150 34.139765 Bran Chex 90 49.12025    Bran Flakes 90 53.31381 Mueslix Crispy Blend 160 30.313351 Cap'n Crunch 120 18.04285 Multi-Grain Cheerios 100 40.105965 Cheerios 110 50.765 Nut&Honey Crunch 120 29.924285 Cinnamon Toast Crunch 120 19.82357 Nutri-Grain Almond-Raisin 140 40.69232 Clusters 110 40.40021 Nutri-grain Wheat 90 59.642837 Cocoa Puffs 110 22.73645 Oatmeal Raisin Crisp 130 30.450843 Corn Chex 110 41.44502 Post Nat. Raisin Bran 120 37.840594 Corn Flakes 100 45.86332 Product 19 100 41.50354 Corn Pops 110 35.78279 Puffed Rice 50 60.756112 Count Chocula 110 22.39651 Puffed Wheat 50 63.005645 Cracklin' Oat Bran 110 40.44877 Quaker Oat Squares 100 49.511874 Cream of Wheat (Quick) 100 64.53382 Quaker Oatmeal 100 50.828392    Raisin Bran 120 39.259197 Crispix 110 46.89564 Raisin Nut Bran 100 39.7034 Crispy Wheat & Raisins 100 36.1762 Raisin Squares 90 55.333142    Rice Chex 110 41.998933 Double Chex 100 44.33086 Rice Krispies 110 40.560159 Froot Loops 110 32.20758 Shredded Wheat 80 68.235885 Frosted Flakes 110 31.43597 Shredded Wheat ‘n’ Bran 90 74.472949 Frosted Mini-Wheats 100 58.34514       Shredded Wheat spoon size 90 72.801787 Fruit & Fibre Dates, Walnuts & Oats 120 40.91705       Smacks 110 31.230054 Fruitful Bran 120 41.01549 Special K 110 53.131324 Fruity Pebbles 110 28.02577 Strawberry Fruit Wheats 90 59.363993 Golden Crisp 100 35.25244    Golden Grahams 110 23.80404 Total Corn Flakes 110 38.839746 Grape Nuts Flakes 100 52.0769 Total Raisin Bran 140 28.592785 Grape-Nuts 110 53.37101 Total Whole Grain 100 46.658844 Great Grains Pecan 120 45.81172 Triples 110 39.106174 Honey Graham Ohs 120 21.87129 Trix 110 27.753301 Honey Nut Cheerios 110 31.07222 Wheat Chex 100 49.787445 Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 9 / 15

It can be seen that the two variables are strongly correlated with a negative correlation of   Roughly speaking, 69% of the total variation in both variables is actually "covariation," or variation in one variable that is duplicated by similar variation in the other variable. Can we use this fact to reduce the number of variables, while making maximum use of their unique contributions to the overall variation? Since there is redundancy in the information that the two variables contain, it might be possible to reduce the two variables to a single variable without losing too much information. The idea in PCA is to find a linear combination of the two variables that contains most, even if not all, of the information, so that this new variable can replace the two original variables. Information here is in the sense of variability: What can explain the most variability among the 77 cereals? The total variability here is the sum of the variances of the two variables, which in this case is 379.63 + 197.32 = 577. This means that calories accounts for 66% = 379.63/577 of the total variability, and rating for the remaining 34%. If we drop one of the variables for the sake of dimension reduction, we lose at least 34% of the total variability. Can we redistribute the total variability between two new variables in a more polarized way? If so, it might be possible to keep only the one new variable that (hopefully) accounts for a large portion of the total variation. Figure 4.8 shows a scatterplot of rating versus calories. The line z1 is the direction in which the variability of the points is largest. It is the line that captures the most variation in the data ifwe decide to reduce the dimensionality of the data from two to one. Among all possible lines, it is the line for which, if we project the points in the dataset orthogonally to get a set of77 (one-dimensional) values, the variance of the z1 values will be maximum. This is called the first principal component. It is also the line that minimizes the sum-of-squared perpendicular distances from the line. The z2 axis is chosen to be perpendicular to the z1-axis. In the case of two variables, there is only one line that is perpendicular to z1, and it has the second largest variability, but its information is uncorrelated with z1. This is called the second principal component. In general, when we have more than two variables, once we find the direction z1 with the largest variability, we search among all the orthogonal directions to z1 for the one with the next highest variability. That is z2. The idea is then to find the coordinates of these lines and to see how they redistribute the variability.   FIGURE 4.8: SCATTERPLOT OF RATING VS. CALORIES FOR 77 BREAKFAST CEREALS, WITH THE TWO Honey-comb 110 28.74241 Wheaties 100 51.592193    Wheaties Honey Gold 110 36.187559 Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 10 / 15

PRINCIPAL COMPONENT DIRECTIONS    FIGURE 4.9: OUTPUT FROM PRINCIPAL COMPONENTS ANALYSIS OF CALORIES AND RATING  Figure 4.9 shows the XLMiner output from running PCA on these two variables. The principal components table gives the weights that are used to project the original points onto the two new directions. The weights for z1 are givenby(-0.847, 0.532), and for z2 they are given by (0.532, 0.847). Figure 4.9 gives the reallocated variance: z1 accounts for 86% of the total variability and z2 for the remaining 14%. Therefore, if we drop z2, we still maintain 86% of the total variability. The weights are used to compute principal component scores, which are the projected values of calories and rating onto the new axes (after subtracting the means). Figure 4.10 shows the scores for the two dimensions. The first column is the projection onto z1 using the weights (−0.847, 0.532). The second column is the projection onto z2 using the weights (0.532, 0.847). For example, the first score for the 100% Bran cereal (with 70 calories and a rating of 68.4) is (−0.847)(70 − 106.88) + (0.532)(68.4 − 42.67) = 44.92.   FIGURE 4.10: PRINCIPAL SCORES FROM PRINCIPAL COMPONENTS ANALYSIS OF CALORIES AND RATING FOR THE FIRST 17 CEREALS  Note that the means of the new variables z1 and z2 are zero (because we have subtracted the mean of each variable). The Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 11 / 15

sum of the variances var(z1) + var(z2) is equal to the sum of the variances of the original variables, calories and rating. Furthermore, the variances of z1 and z2 are 498 and 79, respectively, so the first principal component, z1, accounts for 86% of the total variance. Since it captures most of the variability in the data, it seems reasonable to use one variable, the first principal score, to represent the two variables in the original data. Next, we generalize these ideas to more than two variables. Principal Components Let us formalize the procedure described above so that it can easily be generalized to p> > 2 variables. Denote by X1, X2, …, Xp the original p variables. InPCAwe are looking for a set of new variables Z1, Z2, …, Zp that are weighted averages of the original variables (after subtracting their mean):   where each pair of Z's has correlation = 0. We then order the resulting Z's by their variance, with Z1 having the largest variance and Zp having the smallest variance. The software computes the weights ai, j, which are then used in computing the principal component scores. A further advantage of the principal components compared to the original data is that they are uncorrelated (correlation coefficient = 0). If we construct regression models using these principal components as independent variables, we will not encounter problems of multicollinearity. Let us return to the breakfast cereal dataset with all 15 variables, and apply PCA to the 13 numerical variables. The resulting output is shown in Figure 4.11. For simplicity, we removed three cereals that contained missing values. Note that the first three components account for more than 96% of the total variation associated with all 13 of the original variables. This suggests that we can capture most of the variability in the data with less than 25% of the number of original dimensions in the data. In fact, the first two principal components alone capture 92.6% of the total variation. However, these results are influenced by the scales of the variables, as we describe next.   FIGURE 4.11: PCA OUTPUT USING ALL 13 NUMERICAL VARIABLES IN THE BREAKFAST CEREALS DATASET. RESULTS ARE GIVEN FOR THE FIRST SEVEN PRINCIPAL COMPONENTS  Normalizing the Data A further use of PCA is to understand the structure of the data. This is done by examining the weights to see how the original variables contribute to the different principal components. In our example it is clear that the first principal component is dominated by the sodium content of the cereal: it has the highest (in this case, positive) weight. This means that the first principal component is measuring how much sodium is in the cereal. Similarly, the second principal component seems to be measuring the amount of potassium. Since both these variables are measured in milligrams, whereas the other nutrients are measured in grams, the scale is obviously leading to this result. The variances of potassium and sodium Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 12 / 15

are much larger than the variances of the other variables, and thus the total variance is dominated by these two variances. A solution is to normalize the data before performing the PCA. Normalization (or standardization) means replacing each original variable by a standardized version of the variable that has unit variance. This is easily accomplished by dividing each variable by its standard deviation. The effect of this normalization (standardization) is to give all variables equal importance in terms of the variability. When should we normalize the data like this? It depends on the nature of the data. When the units of measurement are common for the variables (e.g., dollars), and when their scale reflects their importance (sales of jet fuel, sales of heating oil), it is probably best not to normalize (i.e., not to rescale the data so that they have unit variance). If the variables are measured in quite differing units so that it is unclear how to compare the variability of different variables (e.g., dollars for some, parts per million for others) or if for variables measured in the same units, scale does not reflect importance (earnings per share, gross revenues), it is generally advisable to normalize. In this way, the changes in units of measurement do not change the principal components' weights. In the rare situations where we can give relative weights to variables, we multiply the normalized variables by these weights before doing the principal components analysis. Thus far, we have calculated principal components using the covariance matrix. An alternative to normalizing and then performing PCA is to perform PCA on the correlation matrix instead of the covariance matrix. Most software programs allow the user to choose between the two. Remember that using the correlation matrix means that you are operating on the normalized data. Returning to the breakfast cereal data, we normalize the 13 variables due to the different scales of the variables and then perform PCA (or equivalently, we use PCA applied to the correlation matrix). The output is shown in Figure 4.12. Now we find that we need 7 principal components to account for more than 90% of the total variability. The first 2 principal components account for only 52% of the total variability, and thus reducing the number of variables to 2 would mean losing a lot of information. Examining the weights, we see that the first principal component measures the balance between 2 quantities: (1) calories and cups (large positive weights) versus (2) protein, fiber, potassium, and consumer rating (large negative weights). High scores on principal component 1 mean that the cereal is high in calories and the amount per bowl, and low in protein, fiber, and potassium. Unsurprisingly, this type of cereal is associated with a low consumer rating. The second principal component is most affected by the weight of a serving, and the third principal component by the carbohydrate content. We can continue labeling the next principal components in a similar fashion to learn about the structure of the data.   FIGURE 4.12: PCA OUTPUT USING ALL NORMALIZED 13 NUMERICAL VARIABLES IN THE BREAKFAST CEREALS DATASET. RESULTS ARE GIVEN FOR THE FIRST SEVEN PRINCIPAL COMPONENTS  When the data can be reduced to two dimensions, a useful plot is a scatterplot of the first versus the second principal scores with labels for the observations (if the dataset is not too large). To illustrate this, Figure 4.13 displays the first two principal component scores for the breakfast cereals. Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 13 / 15

  FIGURE 4.13: SCATTERPLOT OF THE SECOND VS. FIRST PRINCIPAL COMPONENTS SCORES FOR THE NORMALIZED BREAKFAST CEREAL OUTPUT  We can see that as we move from left (bran cereals) to right, the cereals are less "healthy" in the sense of high calories, low protein and fiber, and so on. Also, moving from bottom to top, we get heavier cereals (moving from puffed rice to raisin bran). These plots are especially useful if interesting clusterings of observations can be found. For instance, we see here that children's cereals are close together on the middle-right part of the plot. Using Principal Components for Classification and Prediction When the goal of the data reduction is to have a smaller set of variables that will serve as predictors, we can proceed as follows: Apply PCA to the training data. Use the output to determine the number of principal components to be retained. The predictors in the model now use the (reduced number of) principal scores columns. For the validation set we can use the weights computed from the training data to obtain a set of principal scores by applying the weights to the variables in the validation set. These new variables are then treated as the predictors. [1]The data are available at http://lib.stat.cmu.edu/DASL/Stories/HealthyBreakfast. html. 4.8 Dimension Reduction Using Regression Models In this chapter we discussed methods for reducing the number of columns using summary statistics, plots, and principal components analysis. All these are considered exploratory methods. Some of them completely ignore the output variable (e.g., PCA), whereas in other methods we informally try to incorporate the relationship between the predictors and the output variable (e.g., combining similar categories, in terms of their behavior with y). Another approach to reducing the number of predictors, which directly considers the predictive or classification task, is by fitting a regression model. For prediction a linear regression model is used (see Chapter 6), and for classification a logistic regression model (see Chapter 10) is used. In both cases we can employ subset selection procedures that algorithmically choose a subset of variables among the larger set (see details in the relevant chapters). Fitted regression models can also be used to further combine similar categories: categories that have coefficients that are not statistically significant (i.e., have a high p-value) can be combined with the reference category because their distinction from the reference category appears to have no significant effect on the output variable. Moreover, categories that have similar coefficient values (and the same sign) can often be combined because their effect on the output variable is similar. See the example in Chapter 10 on predicting delayed flights for an illustration of how regression models can be used for dimension reduction. 4.9 Dimension Reduction Using Classification and Regression Trees Another method for reducing the number of columns and for combining categories of a categorical variable is by applying classification and regression trees (see Chapter 9). Classification trees are used for classification tasks and regression trees for prediction tasks. In both cases the algorithm creates binary splits on the predictors that best classify/predict the outcome (e.g., above/below age 30). Although we defer the detailed discussion to Chapter 9, we note here that the resulting tree diagram can be used for determining the important predictors. Predictors (numerical or categorical) that do Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 14 / 15

not appear in the tree can be removed. Similarly, categories that do not appear in the tree can be combined. Problems 4.1   Breakfast Cereals. Use the data for the breakfast cereal example in Section 4.7 to explore and summarize the data as follows: (Note that a few records contain missing values; since there are just a few, a simple solution is to remove them first. You can use the "Missing Data Handling" utility in XLMiner.) a.Which variables are quantitative/numerical? Which are ordinal? Which are nominal? b.Create a table with the average, median, min, max, and standard deviation for each of the quantitative variables. This can be done through Excel's functions or Excel's Tools > DataAnalysis > DescriptiveStatistics menu. c.Use XLMiner to plot a histogram for each of the quantitative variables. Based on the histograms and summary statistics, answer the following questions: i.Which variables have the largest variability? ii.Which variables seem skewed? iii.Are there any values that seem extreme? d.Use XLMiner to plot a side-by-side boxplot comparing the calories in hot versus cold cereals. What does this plot show us? e.Use XLMiner to plot a side-by-side boxplot of consumer rating as a function of the shelf height. If we were to predict consumer rating from shelf height, does it appear that we need to keep all three categories of shelf height? f.Compute the correlation table for the quantitative variable (use Excel's Tools > Data-Analysis > Correlation menu). In addition, use XLMiner to generate a matrix plot for these variables. i.Which pair of variables is most strongly correlated? ii.How can we reduce the number of variables based on these correlations? iii.How would the correlations change if we normalized the data first? g.Consider the first column on the left in Figure 4.11. Describe briefly what this column represents.  4.2   Chemical Features of Wine. Figure 4.14 shows the PCA output on data (nonnormal-ized) in which the variables represent chemical characteristics of wine, and each case is a different wine. a.The data are in the file Wine.xls. Consider the row near the bottom labeled "Variance" Explain why column 1's variance is so much greater than that of any other column. b.Comment on the use of normalization (standardization) in part (a). Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying ProhibitedPage 15 / 15

  FIGURE 4.14: PRINCIPAL COMPONENTS OF NONNORMALIZED WINE DATA   4.3   University Rankings. The dataset on American college and university rankings (available from www.dataminingbook.com) contains information on 1302 American colleges and universities offering an undergraduate program. For each university there are 17 measurements that include continuous measurements (such as tuition and graduation rate) and categorical measurements (such as location by state and whether it is a private or a public school). a.Remove all categorical variables. Then remove all records with missing numerical measurements from the dataset (by creating a new worksheet). b.Conduct a principal components analysis on the cleaned data and comment on the results. Should the data be normalized? Discuss what characterizes the components you consider key.  4.4   Sales of Toyota Corolla Cars. The file ToyotaCorolla.xls contains data on used cars (Toyota Corollas) on sale during late summer of 2004 in The Netherlands. It has 1436 records containing details on 38 attributes, including Price, Age, Kilometers, HP, and other specifications. The goal will be to predict the price of a used Toyota Corolla based on its specifications. a.Identify the categorical variables. b.Explain the relationship between a categorical variable and the series of binary dummy variables derived from it. c.How many dummy binary variables are required to capture the information in a categorical variable with N categories? d.Using XLMiner's data utilities, convert the categorical variables in this dataset into dummy binaries, and explain in words, for one record, the values in the derived binary dummies. e.Use Excel's correlation command (Tools > DataAnalysis > Correlation menu) to produce a correlation matrix and XLMiner's matrix plot to obtain a matrix of all scatterplots. Comment on the relationships among variables. Data Mining for Business Intelligence: Concepts, Techniques, and Applications in Microsoft Office Excel with XLMiner, Second EditionReprinted for WRFSM/I300634, SAPJohn Wiley & Sons (US), John Wiley & Sons, Inc. (c) 2010, Copying Prohibited