Book Image

R Machine Learning Essentials

By : Michele Usuelli
Book Image

R Machine Learning Essentials

By: Michele Usuelli

Overview of this book

Table of Contents (15 chapters)
R Machine Learning Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Modifying the features


Our features are attributes that describe the flag, and some of them might not be in the right format. In this section, we will take a look at each feature and transform it if necessary.

In order to keep track of which features we have already processed, let's start defining an empty vector namesProcessed, which contains the features that we have already processed. When we transform a feature, we add the feature name into namesProcessed:

namesProcessed <- c()

Let's start with the numeric columns, such as red, which have two possible outcomes: 0, in case the flag contains red and 1 otherwise. The red variable defines an attribute, so it should be categorical instead of numeric. Then, we can convert red into a feature that is yes if the color is red and no otherwise.

If we take a look at the charts of each feature, we notice that some of them display only two values that are always 0 and 1. In order to convert each of them into the yes and no format, we can use a for...