LR:

import numpy as np
import matplotlib.pyplot as plt

def gene_dataset(opt='linear'):
    pos_num , neg_num = 100, 100
    X = np.zeros((2,pos_num+neg_num))
    Y = np.zeros((1,pos_num+neg_num))
    
    if opt == 'linear':
        x1 = np.random.normal(loc=-1,scale=3,size=(1,pos_num)) # 正态分布 均值 方差 样本个数
        
        X[0,:pos_num] = x1
        X[1,:pos_num] = 2*x1+10+0.1*x1**2 + np.random.normal(loc=0,scale=5,size=(1,pos_num)) 
        Y[0,:pos_num] = 1

        x2 = np.random.normal(loc=1,scale=3,size=(1,neg_num)) # 正态分布 均值 方差 样本个数
        
        X[0,pos_num:] = x1
        X[1,pos_num:] = 2*x1-5-0.1*x1**2 + np.random.normal(loc=0,scale=5,size=(1,neg_num)) 
        Y[0,pos_num:] = 0
        
    return X,Y

def plotData(X,Y):
    
    plt.figure()
    pos_idx = (Y==1);
    pos_idx = pos_idx[0,:];
    neg_idx = (Y==0);
    neg_idx = neg_idx[0,:];
    plt.plot(X[0,pos_idx],X[1,pos_idx],'r+')
    plt.plot(X[0,neg_idx],X[1,neg_idx],'bo')
    
X,Y= gene_dataset()
plotData(X,Y)

更多文章请关注《万象专栏》