Machine Learning Foundations(NTU) 第一次作业

这篇博客介绍了在NTU机器学习基础课程中关于感知机学习算法(PLA)的第一次作业。内容包括实现PLA的原始循环和随机循环版本,并分析平均更新次数。此外,还探讨了Pocket PLA算法,通过50次更新和100次更新对比在测试集上的错误率,并进行多次实验求平均值。
摘要由CSDN通过智能技术生成

Machine Learning Foundations(NTU) 第一次作业

PLA

DATA: https://d396qusza40orc.cloudfront.net/ntumlone%2Fhw1%2Fhw1_15_train.dat
Each line of the data set contains one (xn,yn) with xn∈R4. T
he first 4 numbers of the line contains the components of xn orderly, the last number is yn.
Please initialize your algorithm with w=0 and take sign(0) as −1

  • Question 15:

    Implement a version of PLA by visiting examples in the naive cycle using the
    order of examples in the data set. Run the algorithm on the data set.
    What is the number of updates before the algorithm halts?

  • Question 16:

    Implement a version of PLA by visiting examples in fixed, pre-determined random
    cycles throughout the algorithm. Run the algorithm on the data set. Please repeat
    your experiment for 2000 times, each with a different random seed. What is the average
    number of updates before the algorithm halts?

  • Question 17:

    Implement a version of PLA by visiting examples in fixed, pre-determined random cycles
    throughout the algorithm, while changing the update rule to be:
    wt+1 = wt + alpha * yn(t)xn(t)
    with alpha =0.5. Note that your PLA in the previous Question corresponds to alpha=1.
    Please repeat your experiment for 2000 times, each with a different random seed.
    What is the average number of updates before the algorithm halts?

import urllib2
import numpy as np
import random

# url = 'https://d396qusza40orc.cloudfront.net/ntumlone%2Fhw1%2Fhw1_15_train.dat'
# f = urllib2.urlopen(url)
# with open("hw1_15_train.dat", "wb") as code:
#    code.write(f.read())

def train_PLA():
    code = open("hw1_15_train.dat", "r")
    lines = code.readlines()
    xn = np.zeros((len(lines), 5)).astype(np.float)
    yn = np.zeros((len(lines),)).astype(np.int)
    learn_rate = 0.5

    for i in range(0, len(lines)):
        
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值