Pattern Classification(1)_perceptron
利用python产生数据,数据分布如图

产生数据并导出到文件‘data.csv’
import pandas as pd
import numpy as np
from pandas import DataFrame,Series
import math
import matplotlib.pyplot as ply
#Region A :center (0,0),width w,radius 20,number of data 500
w = 8
theata = np.random.uniform(0,math.pi,500)
ra = np.random.uniform(-w/2,w/2,500)
xa = [math.cos(theata[i])*(20+ra[i]) for i in range(500)]
ya = [math.sin(theata[i])*(20+ra[i]) for i in range(500)]
#ply.plot(xa,ya,'.b')
#Region B :center (20,d),width w,radius 20,number of data 500
b = -10
theatb = np.random.uniform(-math.pi,0,500)
rb = np.random.uniform(-w/2,w/2,500)
xb = [20+math.cos(theatb[i])*(20+rb[i]) for i in range(500)]
yb = [b+math.sin(theatb[i])*(20+rb[i]) for i in range(500)]
#ply.plot([xa,xb],[ya,yb],'.b')
xa.extend(xb)
ya.extend(yb)
df = DataFrame({'x':xa,'y':ya})
df.to_csv('data.csv')
浙公网安备 33010602011771号