tensorflow基础篇-2
#-*- coding:utf-8 -*- import tensorflow as tf sess=tf.Session() #整流水线单元relu print sess.run(tf.nn.relu([-3.,3,10.])) #抵消relu激励函数的线性增长部分 print sess.run(tf.nn.relu6([-3.,3.,10.])) #segmoid函数:1/(1+exp(-x)) print sess.run(tf.nn.sigmoid([-1.,0.,1.])) #双面正切segmoid:(exp(x)-exp(-x))/(exp(x)+exp(-x)) print sess.run(tf.nn.tanh([-1.,0.,1.])) #softsign:x/(abs(x)+1) print sess.run(tf.nn.softsign([-1.,0.,1.])) #softplus:log(exp(x)+1) print sess.run(tf.nn.softplus([-1.,0.,1.])) #ELU激励函数:(exp(-x)+1) if x<0 else x print sess.run(tf.nn.elu([-1.,0.,1.]))
#-*- coding:utf-8 -*- from sklearn import datasets #加载鸢尾花卉数据集: # 150数据集 # 每个数据集50个样本 iris=datasets.load_iris() print len(iris.data) print len(iris.target) print iris.target[0] print set(iris.target) # #加载波士顿房价,506个放假样本,14个特征值 import requests housing_url='https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data' housing_header=['CRIM','ZN','INDUS','CHAS','NOX','RM','AGE','DIS','RAD','TAX','PTRATIO','B','LSTAT','MEDV0'] housing_file=requests.get(housing_url) print housing_file.text housing_data=[[float(x) for x in y.split(' ') if len(x)>=1] for y in housing_file.text.split('\n') if len(y)>=1] print len(housing_data) print len(housing_data[0]) #MNIST手写字体库 from tensorflow.examples.tutorials.mnist import input_data mnist=input_data.read_data_sets("MNIST_data",one_hot=True) print len(mnist.train.images) print mnist.train.images print len(mnist.test.images) print mnist.test.images print len(mnist.validation.images) print mnist.validation.images print mnist.train.labels[1,:]