PLA算法的实现

本文介绍了使用Python实现的PLA(Perceptron Learning Algorithm)算法。分为DataEmit.py、PLA.py和PLA2.py三个部分。DataEmit.py生成随机数据并存储为train.txt,PLA.py和PLA2.py读取该文件数据,应用PLA算法。PLA2.py还展示了使用PLA前后的分类结果对比。运行环境为Windows 10,Python 3.6.3,依赖库包括numpy、matplotlib、random和argparse。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PLA learning algorithm

background

This program is a basic implementation of a PLA algorithm in Python which is divided into two parts according to requirements.

DataEmit.py --To generate random numbers and the result is stored in the train.txt file.

train.txt --Stored random data which generated by DataEmit.py.

PLA.py – read the data from train.txt convert the data, and input it into the PLA algorithm.Only input train.txt and output the result of PLA algorithm .

PLA2.py – read the data from train.txt convert the data, and input it into the PLA algorithm.Inputing trian.txt and w. Showing the difference between using PLA and without using PLA.

Requirements

My code has been tested on windows10 and using python 3.6.3.

There are some general library requirements for the project aThe general requirements are as follows.

  • numpy 1.4.1
  • matplotlib 2.2.2
  • random 1.14.5
  • argparse1.1

usege

dataemit.py

In command prompt, find the path where the dataemit.py file is located.

python dataemit.py [5,3,2] 10 10

Note: Please input in strict accordance with this format, do not add more “,” or " ".
Input [w0,w1,w2] specifies the line.
m is the number of points with label“+”.
n is the number of points with label “-“.

The program output a file named “train.txt”, which contains all the data points with labels.

# -*- coding: utf-8 -*-
"""
Created on Tue Sep 17 15:11:11 2019

@author: Zhao Zumin

"""
import numpy as np
import random
import argparse

parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
#parser.add_argument("dataemit", help="input w,m and n",type=int)parser = argparse.ArgumentParser()
group.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("w", type=list, help="input w")
parser.add_argume
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值