Supervised Machine Learning: Regression and Classification 1


在这里插入图片描述

You can learn ML&DL in coursera.

1 Supervised vs. Unsupervised Machine Learning

1.1 Supervised Machine Learning

Supervised learning learns from being given "right answer".
x to y mapping

input -> output
email -> spam
audio -> transcript
English -> Chinese
  • Regression:
    predict a number of infinitely many possible outputs. (House price prediction)
  • Classification:
    predict categories of small number of possible outputs. (cancer)

1.2 Unsupervised Machine Learning

Unsupervised machine learning is a super of supervised machine learning, beacuse there are no any given labels. It can find sonething interesting in unlabled data.

  • Clustering:

Data only comes with inputs x, but not output labels y. Algorithm has to find structure in the data.
Group similar data points together: google news, DNA microarray, grouping customer.

  • Anomaly detection:
    Find unusual data points.
  • Dimensionality reduction:
    Compress data using fewer number.

1.3 Jupyter Notebooks

We run Python in Jupyter notebooks.

#This is  a 'Code' Cell
print("This is  code cell")

This is  code cell

We use the python f-string style

# print statements
variable = "right in the strings!"
print(f"hello, world")
print(f"{
     variable}")

hello, world
right in the strings!

2 Regression Model

2.1 Linear Regression Model

  • training set:
    x = “input” varialble (feature)
    y = “output” variable ("target")
    m = number of training examples
  • learning algorithm:
    x (feature) —> f (model)—> y-hat (prediction/estimated y)
  • model f:
    f_w,b(x) = wx + b
  • w: weight
  • b: bias

2.2 Model Representation in Jupyter Notebooks

scientific computing library NumPy and plotting data library Matplotlib

import numpy as np
import matplotlib.pyplot as plt
plt.style.use('./deeplearning.mplstyle')
  • How to predict house price for follows?
    size price
    1 300
    2 500
    for size = 1.5, price = ?

input feature x and target y

x_train = np.array([1.0, 2.0])
y_train = np.array([300.0, 500.0])
print(f"x_train = {
     x_train}")
print(f"y_train = {
     y_train}")

x_train = [1. 2.]
y_train = [300. 500.]

We use x_train.shape[0] to denote the number m of training examples. .shape[n] is the length number of nth dimension. You can also use len(x_train), it is same.

print(f"x_train.shape: {
     x_train.shape}")
m = x_train.shape[0]
#m = len(x_train)
print(f"Number of training examples is: {
     m}")

x_train.shape: (2,)
Number of training examples is: 2

Our training example is x_i, y_i.

i = 0 # Change this to 1 to see (x^1, y^1)

x_i = x_train[i]
y_i = y_train[i]
print(f"(x^({
     i}), y^({
     i})) = ({
     x_i}, {
     y_i})")

(x^(0), y^(0)) = (1.0, 300.0)

Plot the data points
plt.scatter is the plot scatter points, x means marker style, r means red.

# Plot the data points
plt.scatter(x_train, y_train, marker='x', c='r')
# Set the title
plt.title("Housing Prices")
# Set the y-axis label
plt.ylabel('Price (in 1000s of dollars)')
# Set the x-axis label
plt.xlabel('Size (1000 sqft)')
plt.show()

在这里插入图片描述
Now we use our linear regression model f_w,b(x) = wx + b;
The weight w and bias b

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值