In this article, we will train a machine learning model from scratch, convert it to CoreML model, and finally use the generated CoreML model to write a simple iOS application. The focus of the writing in no way is to develop a perfect model, rather to show how we can practically use a trained model. We assume readers are somewhat familiar with Scikit and machine learning basics.

The dataset comes from [1] and model development part is loosely based on [1].

Train ML model:

To give some overview of data, this dataset represents features to distinguish between different Iris flowers. To start with we will load the dataset and examine various properties.

Below code is used to load the dataset —

import pandas as pd iris_data = pd.read_csv(‘iris-data.csv’)

iris_data.head()

head() method will show top five dataframes as below which shows there are four features and a class for various Iris types —

Top 5 dataframes

The info() method is used to get quick description about the data —

iris_data.info()

Info about data

From information printed, we can see there are total 150 rows. Also, petal_width_cm has 145 entries, that means some values are missing. We will take care of this later.

We try to examine the unique classes with —

iris_data[‘class’].unique()

which outputs —