All the codes in the following can be run in the original post. We hope readers can modify, debug and even fiddle with the code freely in addition to reading and running the code, and try the difference of output results under different training data and model parameters.

Portal: Three minutes seems crazy, but five minutes will open the door to machine learning.


The era of machine learning is here, and it’s hard to say what it will accomplish, but it will certainly change the way software engineers solve problems.

At present, machine learning has been widely applied in various fields by many companies, such as Apple’s Apple ARKit to create richer and more layered user experience, Amazon’s Amazon Echo to answer complex user questions, and HP’s machine learning technology to solve 3D printing problems. Machine learning is a very powerful technology, and programmers should learn how to use machine learning to solve technology, preferably not in the future, but now.

Applied machine learning

Machine learning has many moving parts. In this article, I’ll explain machine learning by writing some code for you, and then discuss what you can do to prepare for the next step.

Let’s start by thinking about how software was written before machine learning. Software engineers solve specific problems by giving step-by-step instructions to computers.

Let’s take the example of banking. For example, we want to write a program that predicts whether borrowers will pay back their loans. We could write a program to analyze their user profiles and set parameters for key variables:

  • Credit Score

  • Loan amount

  • Type of loan

  • Length of membership

The program logic would look like this:

If the complexity of the problem is high, manually adjusting parameters and writing instructions can be difficult and sometimes impossible. Imagine the difficulty of programming an object recognition system.

But machines can look at examples and learn how to solve these problems.

With machine learning, programmers can train a machine learning model to learn from data from thousands of lenders. The model can also be updated over time to respond to new trends and more data. For example, after a security breach in 2017 at the international credit giant Equifax, credit scores from equifAx became less valuable than data from other credit reporting agencies. If this is to be reflected in real loan results, machine learning models can adjust the parameters to reduce the weight of credit scores provided by Equifax. Given enough data, the machine learning model trains itself to find the optimal parameters.

This technique is called supervised learning and will be used in subsequent tutorials. (The other two more common techniques are unsupervised and reinforcement learning.)

Building housing price forecast model tutorial

The fastest way to learn machine learning technology is to try to build a machine learning model, so let’s build our own housing price prediction model. Assume that each house has a base value of $240,000, and each additional bedroom adds $15,000 (K represents 1,000 below for numerical convenience).

As follows:

Predicting house prices requires a simple linear model :(y = mx + b). We can use this formula:

Now let’s build a machine learning model to do this. By using the training data, I want the model to find the values of m and B, which we know are 15 and 240, respectively.

We write programs in Python. Create a new Python file called home_price. Py with the following code. In the code, we first import data and data, set up some initial variables, linear model and loss function. If your environment does not allow this, you can consider installing Docker using the following Docker command:

1. Data Modeling

Click the Run button to import TensorFlow and define variables and models. (Working code: 3 minutes seems crazy, 5 minutes will help you open the door to machine learning!)

2. Model training

Please click the Run button to start the calculation diagram of TensorFlow.

Note: If the page is refreshed, please run the previous code again

In addition to reading and running the code, we hope readers can freely modify, debug and even fiddle with the code, and try the difference of output results under different training data and model parameters.

In the code, we set up some basic placeholders and variables that will be used in training. Then we write a loss function, which is calculated by subtracting y (given or true) from the predicted value. The obtained values are then passed to the optimizer. At each iteration, the optimizer tries to get the value of y and the predicted value by updating the values of the variables M and B.

Next, we use the training data to train the model 1,000 times. Finally, you should get something like this:

What do you think of the values of m and B that you get? Pretty close to what we predicted, right?

Here is a look at how the model is optimized in each iteration. The initial values for m and B start at 1.0 (which we specified in the code), but over time they slowly approach the correct values. We can also see the loss value (forecast — y) slowly decrease to zero.

The figure shows the value and loss of M and B after 100 iterations.

Hopefully the above tutorial has helped you understand the basics of machine learning. In the near future, every programmer will be using machine learning in their actual work, and we are not far away from NPM Install Object-Detect.

New welfare

If you are a machine learning person, but want to learn AI knowledge in the most efficient way, we have a free opportunity to learn AI, let you from zero to master the transformation of AI engineer.

Portal of opportunity:Stamp here!!!!!

This may be your best chance to catch the AI on time, so don’t miss it.