Machine Learning for Engineers - "Hello World!"? Demo

Machine Learning for Engineers - "Hello World!" Demo

There has been so much talk in the media over the recent years on the potential of Machine Learning and AI in general to solve problems that cannot be solved in traditional ways. The main advantage of using Machine Learning is the ability to get computers to make predictions without being explicitly programmed. The potential of AI and Machine Learning is currently being explored and even successfully has been applied in many sectors such as social media, healthcare, and finance. Professor Andrew Ng says "AI is the new electricity". Whether this statement is true or false it remains to be seen.

Machine Learning is a "generic " technology in the sense that its applications are not limited to a specific industry or science. However, it seems some sectors are faster than others in exploring and adopting ML in solving some of their problems. The engineering sector, for example, is quite behind other sectors in investing in ML solutions despite the fact that the tools to exploit ML are very accessible at a quite low cost. Also, it is not strictly a requirement to be a data scientist or an ML expert to be able to explore the potentials of this technology.

I hope in this article to be able to convince you that to start exploring ML, you don't need to have a degree in ML or even be able to write software code. Of course, ultimately having expertise in ML or programming will surely lead to better ML solutions.

The problem I chose in this article to demonstrate the ability of ML in solving engineering challenges is finding the centroid of an arbitrary area.

No alt text provided for this image

Using ML to find the centroid of an arbitrary area is quite an invented?problem since this problem can be explicitly programmed. However, let us imagine for a moment that this is not the case and that the problem cannot be explicitly programmed and we just have lots of previous experiments or observations of arbitrary areas with their centroids, or that the problem can be explicitly programmed but it is computationally expensive and it would take hours or days to find the centroid of an arbitrary area so that it is not practical to deploy such solution in the final product. These are usually the two reasons when ML might shine as an alternative solution.

Now that we know the problem we want to solve (i.e. finding the centroid of an arbitrary area), the first step in the ML solution design is preparing the data to use to train the so-called ML model. This basically means creating or building an ML model to use later to make predictions on data that is different from the training data used to create the model.

For our problem, let us assume some historical data for arbitrary areas with known centroids already exist. And that each area can be plotted on a grid of 10x10 squares. To be able to solve the problem using ML, the data needs to be converted from grid format to tabular format. As an approximation, we will measure how much of the arbitrary area occupies each square on the grid and store the area densities on the grid squares in cells in a table. For example, if a square is fully filled, then the density will be 1.0, and if it is empty, the density is 0.0. After doing this exercise, the same arbitrary areas are represented in a table of 102 columns. The first 100 columns represent the area density in each grid square and the last two are for the centroid value (Xc, Yc). This way each plotted arbitrary area can be a row in the table.

No alt text provided for this image

For the demo purpose, I mimic the historical data of the arbitrary areas by writing a small tool to generate 10000 arbitrary areas and find their centroids mathematically and store this data in tabular format.

No alt text provided for this image

Now that we have the data, the next step is to train the ML model. As I promised, we will not write any code for this, so I will use the ML.NET Model Builder in Visual Studio to train my model. In Visual Studio, you can add a Machine Learning Model and select the scenario for your problem and then feed in the data and wait until your model is trained. For our problem, the right scenario to choose is the "data regression" or "value prediction" scenario. After picking up this scenario and following the wizard steps, we will obtain a zip file that represents our trained ML model. Note that the first 100 columns in the data represent the input (i.e. the ML features) and the last two represent the output (i.e. the ML labels).

Visual Studio ML builder

Of course, there are a few ML solution providers and so you are not limited to the tools used above.

Now the ML model is trained and ready, let us use it. For this, a small test app is written to predict the centroid of arbitrary areas using the trained ML model. And just so that we can compare with the centroid being calculated using the traditional way, the app implements the explicit solution for the centroid problem. In the test app, the user can upload an image representing an arbitrary area or they can draw this directly in the white box. Once the area has been defined, the user can predict the centroid location by clicking on the Calculate button as shown below.

No alt text provided for this image

Below are some random arbitrary areas with the results obtained from the test app for both the accurate mathematical model and the ML model.

No alt text provided for this image

It can be seen that the accuracy of the results from ML varies. Of course, this is expected but that doesn't mean there is nothing we can do to improve our ML model to obtain more accurate predictions. Having a deeper understanding of how ML algorithms work or having a data scientist or an ML expert in the team helps fine-tune any ML solution.

As engineers, we don't design final products based on estimation. However, in many design scenarios, an initial good estimation or prediction for some design aspects is quite useful to the design process as a whole. For example, engineers sometimes use lookup tables to build the initial design or to start an optimization process. In such cases, using ML prediction might be a good starting point for the design process to get a better design or to reduce the time to reach the optimum design. Needless to say, there are still some other applications for ML where engineering problems cannot be explicitly programmed.

I expect that in the coming years we will hear more on the use of ML to solve engineering challenges such as designing a greener future. Finally, I hope in this article I managed to get you a little bit more interested in exploring the potential of ML as part of your toolbox to solve future engineering challenges.

P.S. the source code of the demo can be found here.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了