Although we can create a supervised machine learning algorithm in many different ways, it is suggested to keep in mind a specific workflow, which is applicable for supervised and unsupervised learning. This workflow is presented below:

1. Data Importation:
Data importation is of course to create a machine learning algorithm. Without any data, no computer can learn any patterns about anything. We have learn how to import a data set in R using base R or the readr package.

2. Exploratory Data Analysis (EDA):
As we will learn in the next chapters, we can easily create predictive models if our data set has already an accepted structure. However, good predictive models and machine learning algorithms can be created only after we explore our data very carefully. Understanding our data is an absolute necessity even if eventually we create a predictive model that is so complex that we cannot interpret it. The previous chapters were very important for this step. The statistical framework that we acquired and the data visualization techniques that we learn can really help us on this step.

3. Data Preprocessing:
This step involves handling missing values, encoding categorical variables and any other necessary transformations to prepare the data for modeling. This can be seen as the changes that we want to make to our initial data set based on the exploratory data analysis. For instance, we may see that we have some missing values or some inaccurate data and so we may need to remove these data from our data set. In other words, data preprocessing is a necessary step to ensure that we have high quality data.
It’s essential for ensuring that your data is in a suitable format for the algorithm.

4. Feature Engineering:
This step involves creating new features from the existing ones or transforming features to improve predictive model performance. For instance, during the exploratory data analysis step, we may discover that having a variable in log scale makes more sense based on our goal or we need to combine two variables into one. When we say feature, we essentially mean an independent variable that is prepared to be used for predictive modeling and so the goal of feature engineering is to prepare our independent variables to be used as the best predictors possible for our modeling process.

Many times, feature engineering can be seen as part of the data preprocessing step so in many application, we may see feature engineering as part of data preprocessing process. The difference though is that data preprocessing focuses more on generally fixing data quality issues (e.g. handling missing values) while feature engineering is about ensuring the data set in a suitable format for the algorithm (e.g. the dependent variable can only have values of 0 or 1 in the case of binary classification).

5. Machine Learning Methodology Selection:
After data preprocessing and feature engineering, we are ready to apply machine learning methodologies, which means that our machine can start learning the patterns of our data set. At this stage, we decide which type of model(s) is appropriate to use for our problem. For instance, we can try to use KNN or Decision Tree due to the nature our data set or the assumptions that we make.

6. Model Training and Evaluation:
When we fit a model to our data (that is the model learns the specific patterns of our data set), we say that we *train* our model. As we mentioned, machine learning can be seen as teaching, or training, a dog new tricks. The previous steps that we mentioned are of course very important since if our data set is not of a good quality then our model would also not be of a good quality (in many cases actually we may receive errors when we use modeling functions (we explain practical details in the next chapters).

We need to keep in mind that when we want to train a model, we almost never use our whole data set. In almost every machine learning application, we train our model in a subset of the data set (e.g. 80%). So, if our original data set consists of 10,000 rows, we keep let’s say, 8,000 rows which we use to train our model; this subset is called training set, because is used to train our model.

During the training process though, it makes sense that we want to try different models (even of the same methodology). For instance, we may want to check whether adding an additional predictor would increase the performance of the model. For this purpose, it is advisable to also hold back a subset of the training set, something that is usually called validation set. So, if the validation set is let’s say 10% of the training set, then essentially the training set is 72% and the validation set is 8% of our original data set (we still have not used at all the rest 20%).

7. Prediction on Test Set:
When we believe that our model is good enough, we apply it on the rest 20% percent of our original data set, a subset that is called **test set**, because we use it to test the performance of our model. The test set is needed because it makes sense that our model has learnt the patterns in the training set and as a result, we need to use or model on data that have not been by our model before. In this way, we simulate the scenario that our model is good enough to be used in future and previously unseen situations. It is important to use the test set once or twice at most to check our final results on completely unseen data, otherwise the test set can become part of the training process and is used as validation set. So a test set is different from a validation set in a way that the latter is used as a validation to find the optimal model while the first is used to check the results when we truly believe that our model is ready to be used in practice.

 

Remember, this is a generalized workflow, and the specific steps and their order might vary depending on the problem that we have and the nature of your data. The purpose of this generic workflow is to keep in mind a specific order and discuss the purpose of each step. For instance, during the model training and evaluation step, we may realize that we need to transform a variable to improve the performance. If we transform that variable eventually, we essentially take a step back to use feature engineering and the we continue the training with this new feature.