import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def getData():
r"""
使用numpy构造满足条件的随机数()
:return:
"""
dataX = np.random.randint(1,100,size=(1,100))
dataY = np.random.randint(1,100,size=(1,100))
data = np.concatenate((dataX,dataY), axis = 0)
G1tfa = data > 50
G1tfi = np.logical_and(G1tfa[0,:], G1tfa[1,:])
G1index = np.nonzero(G1tfi)[0]
G1 = data[:, G1index]
G2tfa = data < 50
G2tfi = np.logical_and(G2tfa[0,:], G2tfa[1,:])
G2index = np.nonzero(G2tfi)[0]
G2 = data[:, G2index]
return (G1, G2)
def getDate2():
r"""
使用numpy生成随机数;
使用pandas构造满足条件的随机数;
:return:
"""
df = pd.DataFrame()
df['X'] = np.random.randint(1,100,size=(100))
df['Y'] = np.random.randint(1,100,size=(100))
G1 = df[(df['X']>50) & (df['Y']>50)]
G2 = df[(df['X']<50) & (df['Y']<50)]
return (G1.values.T, G2.values.T)
if __name__ == "__main__":
print("线性回归模型")
G1, G2 = getData()
fig, ax = plt.subplots()
ax.scatter(G1[0,:], G1[1,:])
ax.scatter(G2[0,:], G2[1,:])
fig.show()