Preprocessing CSV files
Sometimes, the data we have comes in a format that's incompatible with libraries we want to use. For example, the Iris dataset file contains a column that contains strings. Many machine learning libraries cannot read such values, because they assume that CSV files contain only numerical values that can be directly loaded to internal matrix representation.
So, before using such datasets, we need to preprocess them. In the case of the Iris dataset, we need to replace the categorical column containing string labels with numeric encoding. In the following code sample, we replace strings with distinct numbers, but in general, such an approach is a bad idea, especially for classification tasks. Machine learning algorithms ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access