刚学习TF,尝试拿sklearn的datasets来做下练习。波士顿房价数据是个不错的选择。
python3.5
tensorflow 0.12
把所有的包import进来
# coding: utf-8
import tensorflow as tf
from sklearn.datasets import load_boston
import matplotlib.pyplot as plt
from sklearn.preprocessing import scale
from sklearn.model_selection import train_test_split
获取数据
boston = load_boston()
# X = scale(boston.data)
# y = scale(boston.target.reshape((-1,1)))
X_train,X_test,y_train,y_test = train_test_split(boston.data,boston.target,test_size=0.1,random_state=0)
X_train = scale(X_train)
X_test = scale(X_test)
y_train = scale(y_train.reshape((-1,1)))
y_test = scale(y_test.reshape((-1,1)))
定义每一层网络结构,写了个add_layer,让添加网络更加灵活。
完全参照莫烦老师:https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/3-1-add-layer/
def add_layer(inputs,input_size,output_size,activation_function=None):
with tf.variable_scope("Weights"<