实类2:将模拟数据制作成内存对象数据集

1.生成模拟数据

import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
#from sklearn.utils import shuffle
def GenerateData(batchsize=100):
    train_X=np.linspace(-1,1,batchsize)
    train_Y=2*train_X+np.random.randn(*train_X.shape)*0.3
    #yield shuffle(train_X,train_Y)#数据打乱处理
    yield train_X,train_Y

2.定义占位符:

 

Xinput=tf.placeholder('float',(None))
Yinput=tf.placeholder('float',(None))

3.建立会话 获取数据

rain_epochs=20
with tf.Session() as sess:
    for epoch in range(train_epochs):
        for x,y in GenerateData():
            xv,yv=sess.run([Xinput,Yinput],feed_dict={Xinput:x,Yinput:y})
            
            print(epoch,' x.shape:',np.shape(xv),' x[:3]:',xv[:3])
0  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
1  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
2  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
3  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
4  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
5  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
6  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
7  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
8  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
9  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
10  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
11  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
12  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
13  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
14  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
15  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
16  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
17  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
18  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]
19  x.shape: (100,)  x[:3]: [-1.         -0.97979796 -0.959596  ]

 4.数据可视化

train_data=list(GenerateData())[0]
plt.plot(train_data[0],train_data[1],'ro',label='Original data')
plt.legend()
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值