Expert systems - 6 Jars
Tags: machinelearning, datascience
Published: 2020-08-02 16:59:25

In an expert system a human establishes the rules and hand codes the rules and the machine executes the rules. In machine learning the machine learns from the data curated by a human and uses functions and parameters to establish a relationship between input and output.

![https://miro.medium.com/max/1433/1*z7TbjUwpkQQ4UxYqgo99Nw.png](https://miro.medium.com/max/1433/1*z7TbjUwpkQQ4UxYqgo99Nw.png)

Let us split the machine learning process into 6 jars and see how these interact with each other to form the complete process of machine learning.

![https://miro.medium.com/max/1636/1*yrmbCvJVyw8EioS6bEzHxw.png](https://miro.medium.com/max/1636/1*yrmbCvJVyw8EioS6bEzHxw.png)

The basic idea of machine learning is to find a function that depends on the features of the given data. It is used to find the output from a number of given inputs. A function can be a series of if-else statements, weights applied to different parameters / features or from a family of functions such as linear , polynomial or non-linear.

The machine learning algorithm tries all the functions and different parameters in the function and ultimately selects the one which best explains the relationship between input and output.

![https://miro.medium.com/max/1633/1*-HdsTTH3d1AcQotv_LvdHw.png](https://miro.medium.com/max/1633/1*-HdsTTH3d1AcQotv_LvdHw.png)

The domain of machine learning has been more successful because of abundant data that is available in different forms such as text, image, video, pictures, voice and tabular data.

The models and learning algorithms are already available open source for everyone to use.

The hardware limitations for computing has been broken with the help of cloud computing and complex tasks can be performed using a simple machine with a web browser.

Lets split machine learning process into six different jars and look into each one of them in detail.

# **Jar 1 — Data**

![https://miro.medium.com/max/1756/1*d9oZEpcKtpdCcFx3K_buEA.png](https://miro.medium.com/max/1756/1*d9oZEpcKtpdCcFx3K_buEA.png)

For machine learning we need useful data and lets look at what form that these data should be in to get meaningful insights from them. So the data can be in the form of text, audio, image and structured data in tabulated form.

![https://miro.medium.com/max/1764/1*UW9lELuyG_evN-TXnQanzA.png](https://miro.medium.com/max/1764/1*UW9lELuyG_evN-TXnQanzA.png)

For example this is a medical image with input part (`x`) and output part (`y`) which tells the presence of an anomaly. The question that the hospital can raise is " Can I tell whether a person is normal or not with these images ? ". For that question to be answered we need the output (`y`) given by the doctors to each and every image of the scan and x is the data of each and every pixel in the scan. If the scan is a 30x30 image then there are 900 RGB values of the image stored in a array. This data can be read by a machine. Here all the data is encoded as numbers and contains 900 real numbers. This is an example of high dimensional data.

- The data should be in `x` and `y`.
- The data should be in machine readable format.

![https://miro.medium.com/max/1759/1*QMSAZ2AY6axXX6lSWHjZ5w.png](https://miro.medium.com/max/1759/1*QMSAZ2AY6axXX6lSWHjZ5w.png)

In this example the text data in the document is represented as real numbers in `x` and output is represented in `y`.

# **Jar 2 — Tasks**

![https://miro.medium.com/max/1749/1*R4vzzzQd_vkg-bXuWB73og.png](https://miro.medium.com/max/1749/1*R4vzzzQd_vkg-bXuWB73og.png)

In this example the input `x` ( red box ) is the text data from description of product and output `y` (green box)is the structured tabulation extracted from the unstructured input `x`.

![https://miro.medium.com/max/1749/1*F9Nn45YkpK4hcU-76RJDkw.png](https://miro.medium.com/max/1749/1*F9Nn45YkpK4hcU-76RJDkw.png)

The tasks can be supervised that is, they have labelled data. Here from the labelled images we can tell classifier to learn the relationship between `x` and `y` and find out whether there's any text in the image (`y` = 1) or not ( `y` = 0 ).

![https://miro.medium.com/max/1755/1*X_tK-u5XpyPkF846LMmRgg.png](https://miro.medium.com/max/1755/1*X_tK-u5XpyPkF846LMmRgg.png)

In this task it is expected to find the box in which the text is present in the image. Here we are trying to find the co-ordinates (`left_x`, `left_y`, `width`, `height`) of the box from the values (`x`) of the image given.

![https://miro.medium.com/max/1756/1*rgH6oKPBB3AnEOpksa06FQ.png](https://miro.medium.com/max/1756/1*rgH6oKPBB3AnEOpksa06FQ.png)

In unsupervised tasks we don’t know the `y` labels. We don't know what each cluster means, like they can be clustered based on colours of the sign or based on the shapes of the sign board. The machine will try to find the pattern and it is upto us to interpret those patterns.

![https://miro.medium.com/max/1746/1*iHlbMJoaD79m_IxONxXTGg.png](https://miro.medium.com/max/1746/1*iHlbMJoaD79m_IxONxXTGg.png)

In this type of unsupervised task the machine generates `x` from `x`. That is from the images given as input it produces an output image that is similar to input images. This is known as generations and is achieved with the help of GAN's (Generative Adversarial Networks).

# **Jar 3 — Models**

![https://miro.medium.com/max/1749/1*NSZn2VxSGyCombgxHfwJLA.png](https://miro.medium.com/max/1749/1*NSZn2VxSGyCombgxHfwJLA.png)

The image is classified as a dog because there is a function which takes the image and classifies it as a dog. The problem that we face at the beginning is that we don’t know what the function is. This is where machine learning comes in to find the function and establish a relationship with `x` and `y` which is the closest approximation of the true relation.

![https://miro.medium.com/max/1758/1*R8-DN12IjEjt8glTTR2gqQ.png](https://miro.medium.com/max/1758/1*R8-DN12IjEjt8glTTR2gqQ.png)

The ŷ is the close approximation of the function. The green line in the graph is our model developed by close machine learning.

![https://miro.medium.com/max/1751/1*HWG1-aIBud-guaXcXYFEVw.png](https://miro.medium.com/max/1751/1*HWG1-aIBud-guaXcXYFEVw.png)

Trying to fit a function through all the points makes it more complex. So we use the concepts of bias-variance tradeoff, overfitting and regularization to control the complexity of the model.

# **Jar 4 — Loss Function**

![https://miro.medium.com/max/1749/1*q-U9d0UUuzkwSVjjdL_0Zg.png](https://miro.medium.com/max/1749/1*q-U9d0UUuzkwSVjjdL_0Zg.png)

Let’s assume that three people build three models for a given function. To determine which model suits the best we can use loss function to solve the problem.

![https://miro.medium.com/max/1756/1*76YkYeu7TT7004jsPXunPw.png](https://miro.medium.com/max/1756/1*76YkYeu7TT7004jsPXunPw.png)

L1,L2,L3 are the loss functions of the three models. We can see that L1 has less value and hence it is a close approximation of the function. A model can be said to have perfect estimate when the loss function equals to 0.

# **Jar 5 — Learning**

![https://miro.medium.com/max/1754/1*fEj8_fsXGTvCs4DjgppGYw.png](https://miro.medium.com/max/1754/1*fEj8_fsXGTvCs4DjgppGYw.png)

The learning algorithm is used to find the parameters a,b,c such that the loss is minimized. There are many optimization solvers which can be used to find a,b,c and this forms the crux of machine learning.

# **Jar 6 — Evaluation**

![https://miro.medium.com/max/1749/1*qqXse8ejrtlHiaY-lUZc8w.png](https://miro.medium.com/max/1749/1*qqXse8ejrtlHiaY-lUZc8w.png)

The data is split into test and train before training the model on the test data. The predictions are made on the test data and accuracy is used to evaluate the model built. All the data collection process , defining the tasks in terms of `x` and `y` , defined a learning algorithm and loss function is done on training data. The goal is to estimate the parameters a,b,c so that the loss on the training data is minimized.