Data cleaning homework
Instructions
- Data cleaning. Remove the rows with missing or garbled categorical data.
- Imputation. Replace the missing or bad numbers with the average of the rest of their column. Bad numbers include text (like NA, ?, or a number written in words), a value that is zero or negative, and a number off by orders of magnitude (like 99999 g).
- Rescaling. Rescale any numeric column with values above 1 by dividing by its maximum.
- Feature engineering. Replace each column of categories (text values) with one-hot columns.
- Make four new tabs, named “inputs_train”, “targets_train”, “inputs_test”, and “targets_test”. Copy the input features, with their column names, into “inputs_train”, and the one-hot fruit columns into “targets_train”. Paste by value (Edit > Paste special > Values only) so the tabs hold numbers rather than formulas.
- Split off a test set of about 20 to 30 percent of the rows. For example, cut the last 10 rows of “inputs_train” and “targets_train” and paste them into “inputs_test” and “targets_test”. Copy the column names into row 1 of each test tab as well.
- Download each of the four tabs as a CSV (File > Download > Comma-separated values).
- Train a classifier in Simbrain to predict the fruit. There are four places to import data, one for each file. In every case, set “Use column names” to yes.
Spreadsheet formulas
These are for Google Sheets, but most also work in Excel. They assume the data runs from row 2 to row 35, with the column names in row 1. Adjust the letters and row numbers to match your sheet.
Impute a cell. To fill a blank, for example C12, with the average of the cells above and below it, type =AVERAGE(C2:C11, C13:C35).
Rescale. To rescale a column, for example column A, type =A2/MAX(A:A) in row 2 of an empty column and fill down.
Copy a column. To copy a column, for example column B, type =B2 in row 2 of an empty column and fill down. The copy updates if the original changes.
One-hot. Type the category names (apple, orange, lemon) as column names in row 1 of three empty columns. For example, if the fruit is in column D and the new columns are G, H, and I, type =IF($D2=G$1,1,0) in G2 and fill down and across.
One-hot by hand. You can also type the 1s and 0s yourself. Type the category names in row 1 of three empty columns as above. Type 0 in row 2 of the first one and drag it across the other two. Then select those three cells and drag down to the last row, so every cell is 0. Finally, go down the rows one at a time and change the 0 under the matching fruit to 1.