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