-

- -

Friday, February 19, 2021

Machine Learning In JavaScript

 .

Machine Learning (ML)

Machine Learning is often considered equivalent with Artifical Intelligence.

This is not correct. Machine learning is a subset of Artificial Intelligence.

Machine Learning is a disipline of AI that uses data to perform supervised or unsupervised machine training.

What is Machine Learning?

ML systems combines Input to produce Predictions.

Key terminologies are:

  • Labels
  • Features
  • Models
  • Training
  • Inference
  • Functions

Machine Learning Labels

In Machine Learning terminology, the label is the thing we want to predict.

It is like the y in a linear graph:

y = ax + b


Machine Learning Features

In Machine Learning terminology, the features are the input.

They are like the x values in a linear graph:

y = ax + b


Machine Learning Models

Model defines the relationship between the label (y) and the features (x).

There are three phases in the life of a model:

  • Data Collection
  • Training
  • Inference

Data Collection

Machine Learning can teach a computer to solve many questions like:

  • Is this cancer?
  • Is this a banana?

Before Machine Learning can start, you need to collect some data.

If you want to predict house prices, you need to collect some information about house prices.


Machine Learning Training

The goal of training is to create a model that can answer our question. Like what is the expected price for a house?


Machine Learning Inference

Inference is when the trained model is used to infer (predict) values using live data. Like putting the model into production.


Using a Linear Regression Function

This Model predicts prices using a linear regression function:

Prices

Example

# Name the Axis
plt.title('House Prices vs Size')
plt.xlabel('Square Meters')
plt.ylabel('Price in Millions')

# Set x and y values
x = np.array([50,60,70,80,90,100,110,120,130,140,150,160])
y = np.array([7,8,8,9,9,9,9,10,11,14,14,15])

# Call Linear Regression Function
slope, intercept, r, p, std_err = stats.linregress(x, y)

# Plot Data
plt.scatter(x, y)
plt.plot(x, slope * x + intercept)
plt.show()
Try it Yourself »

In the example above, the slope and intercept is calculated by a function called linregress.

From Previous Chapter

A linear relationship is written as y = ax + b

Where:

  • y is the price we want to predict
  • a is the slope of the line
  • x are the input values
  • b is the intercept

With Machine Learning

With ML, a linear relationship is written as y = b + wx

Where:

  • y is the label we want to predict
  • w is the weight (the slope)
  • x are the features (input values)
  • b is the intercept

Sometimes there can be many features (input values) with different weights:

y = b + w1x1 + w2x2 + w3x3 + w4x4


.

https://web.archive.org/web/20210220012931/https://www.w3schools.com/ai/ai_machine_learning.asp

.


No comments:

Post a Comment