吴裕雄 python 机器学习-NBYS(2)

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

n = 1000 
xcord0 = []
ycord0 = []
xcord1 = []
ycord1 = []
markers =[]
colors =[]

for i in range(n):
    [r0,r1] = np.random.standard_normal(2)
    myClass = np.random.uniform(0,1)
    if (myClass <= 0.5):
        fFlyer = r0 + 9.0
        tats = 1.0*r1 + fFlyer - 9.0
        xcord0.append(fFlyer)
        ycord0.append(tats)
    else:
        fFlyer = r0 + 2.0
        tats = r1+fFlyer - 2.0
        xcord1.append(fFlyer)
        ycord1.append(tats)
        
fig = plt.figure()
ax = fig.add_subplot(111)
ax.scatter(xcord0,ycord0, marker='^', s=90)
ax.scatter(xcord1,ycord1, marker='o', s=50, c='red')
plt.plot([2,4], label='going up')
plt.show()

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.0, 0.5, 0.01)
s = np.sin(2*np.pi*t)
logS = np.log(s)

fig = plt.figure()
ax = fig.add_subplot(211)
ax.plot(t,s)
ax.set_ylabel('f(x)')
ax.set_xlabel('x')

ax = fig.add_subplot(212)
ax.plot(t,logS)
ax.set_ylabel('ln(f(x))')
ax.set_xlabel('x')
plt.show()

原文地址:https://www.cnblogs.com/tszr/p/10174206.html