
Machine Learning III 101 Continued — Insurance Data set
So after a couple of attempts at Machine Learning, we are now ready to approach Machine Learning from a business angle.
Updated

On this page
Updated November 2026. This was first published on 15 May 2020. The idea is the same. Any number below is what the original piece said then. It is not a new count.
Key takeaways
- So after a couple of attempts at Machine Learning, we are now ready to approach Machine Learning from a business angle.
- I leveraged this great tutorial from Jason Brownlee for this post.
- We will address here some of the questions that we raised at the end of the last post.
Preparing for a Real-Life Machine Learning Project 3 #
So after a couple of attempts at Machine Learning, we are now ready to approach Machine Learning from a business angle. I leveraged this great tutorial from Jason Brownlee for this post.
We will address here some of the questions that we raised at the end of the last post.
What if a decision tree is not the best choice for an algorithm?
How do we know that this model had the highest possible accuracy score? How would we test the other machine algorithm approaches?
How can I tell if some variables have a more direct relationship on the outcome than others?
Before we answer any of these questions, let’s spend some time on data preparation. This step is usually where most of the work happens in a live project.
Data Preparation: #
For this project, I sourced the data from the following link:https://opendata.stackexchange.com/questions/7807/where-can-i-find-automobile-insurance-claims-data-set.
The main steps followed concerning data preparation were as follows.
The first thing to note upon downloading the data was that there is no label of someone being an Excellent Driver, Good Driver, or a Bad Driver.
The creation of the ’label’ was a substantial component of this exercise, as you will see from the steps below.
There are a total of 17 columns or ‘Features’ in this data set. As ‘Feature Selection’ is an essential part of creating an algorithm, we need to examine which of these 17 features are perfect for consideration in our analysis and which ones are not.
I did not find any description of the areas online, so I created my own using the names of the fields.
Out of 17 features, we ended up including 5 in a CSV file.
I then used the following criteria to arrive at the Labels.
Applying this logic resulted in the following distribution of ‘Labels’.
Preparing the Algorithm #
Step 1 ? Load the Data #
As this is a CSV file, we need the ability to read a CSV file as the very first step.
As we did before, we let use the print command to verify if everything is OK with the program. As you can see from the screenshot below, the program does not output the contents of the file, but prints line 2 of the program.
We use the print command to verify if the program can access the contents of the file, and based on the screenshot, it can. We can also see that we have 9,134 rows and six columns.
To verify this, we can use the dataset.shape. As you can see from the screenshot below, the dataset.shape outputs (9134, 6), which confirm the results above.
Step 2 ? Train the Data #
Let’s load the file into an array now.
An array is a data structure that stores values of the same data type. In Python, this is the main difference between arrays and lists. While python lists can contain values corresponding to different data types, arrays in Python can only contain values corresponding to the same data type.
Once the data loads into an array, the data can split into ‘Training’ data and ‘Testing’ data. As we did last time, we will train the data on 80% of the data set, and test it on the remaining 20%.
To do so, we use the following commands.
Upon running the program, there were no errors reported, as shown in the screenshot below.
We then use the print command to see what the program prints when using X and Y.
Printing X confirms that none of the ‘Labels’ are being picked up.
Printing’ Y’ confirms that none of the ‘Features’ are selected.
To split the data to ‘Train’ and ‘Test’ it, we need to import that module from the sklearn library. We will use a ‘random state’ in our data splitting to ensure that the different algorithms we use receive the same amount of data to avoid any bias. Running the library does not result in any errors, as evidenced in the screenshot.
At this point, our data split into Training and Testing data.
Step 3 ? Run Multiple Models #
There are six different models that we can build and test.
The model looks for a pass/fail relationship between variables.
Looks for a linear relationship between two or more classes of objects.
A pattern recognition used for both regression and classification.
o Classification and Regression Trees (CART) ? Use of ‘decision trees’ to go from observations to conclusions.
Calculation of pre and post probabilities approach.
Supports labeling of unlabeled data in an unsupervised environment.
To run these six models concurrently, we can treat these models as a list of models to be used using [].
To append these models to a list named Models, we must import the models from sklearn. We once again run our code and find no errors.
Step 4 - Check Accuracy Score for each Model #
To check the accuracy of each of the six models, we create a list titled ?results?
cv_results = cross_val_score(model, X_train, Y_train, cv=kfold, scoring=‘accuracy’).
print(’%s: %f (%f)’ % (name, cv_results.mean(), cv_results.std())).
from sklearn.model_selection import cross_val_score (to evaluate a score by cross-validation).
Upon running the program, we can see the results for the different models we used in the screenshot below.
output are the mean and the standard deviation of the six algorithms.
In the example above, the Classification and Regression Trees (CART) model has generated an accuracy rate of 93% with a slightly elevated standard deviation. The CART model thus would be the best approach, in this case.
In the next post, we will examine how to use strings (most of the other columns in our data sets) in our algorithms and see if that makes a difference as to which algorithm might be the best one to use.
Questions and answers #
What is the main point? #
So after a couple of attempts at Machine Learning, we are now ready to approach Machine Learning from a business angle.
What else did the original piece say? #
I leveraged this great tutorial from Jason Brownlee for this post.