Example #1
0
def test_data_home():
    # get_data_home will point to a pre-existing folder
    data_home = get_data_home(data_home=DATA_HOME)
    assert_equal(data_home, DATA_HOME)
    assert_true(os.path.exists(data_home))

    # clear_data_home will delete both the content and the folder it-self
    clear_data_home(data_home=data_home)
    assert_false(os.path.exists(data_home))

    # if the folder is missing it will be created again
    data_home = get_data_home(data_home=DATA_HOME)
    assert_true(os.path.exists(data_home))
def test_data_home(data_home):
    # get_data_home will point to a pre-existing folder
    data_home = get_data_home(data_home=data_home)
    assert data_home == data_home
    assert os.path.exists(data_home)

    # clear_data_home will delete both the content and the folder it-self
    clear_data_home(data_home=data_home)
    assert not os.path.exists(data_home)

    # if the folder is missing it will be created again
    data_home = get_data_home(data_home=data_home)
    assert os.path.exists(data_home)
Example #3
0
def test_data_home():
    # get_data_home will point to a pre-existing folder
    data_home = get_data_home(data_home=DATA_HOME)
    assert_equal(data_home, DATA_HOME)
    assert_true(os.path.exists(data_home))

    # clear_data_home will delete both the content and the folder it-self
    clear_data_home(data_home=data_home)
    assert_false(os.path.exists(data_home))

    # if the folder is missing it will be created again
    data_home = get_data_home(data_home=DATA_HOME)
    assert_true(os.path.exists(data_home))
with tf.Session() as sess:
    print(y.eval())
    print(z.eval())  # 为了计算 y 和 z, w和x计算了两次

with tf.Session() as sess:
    y_val, z_val = sess.run([y,z])   #仅计算一次w和x,相当于节省了计算效率
    print(y_val)
    print(z_val)
#201页
import numpy as np
#from sklearn.datasets import iris
#housing = fetch_califonia_housing()

from sklearn import datasets
#清空sklearn环境下所有数据
datasets.clear_data_home()

#不加return命令,可以得到dictionary,并能知道数据每列含义
boston = datasets.load_boston()
boston.keys()
#载入波士顿房价数据
#X,y = datasets.load_boston(return_X_y=True)

m, n = boston.data.shape
#np.c_指将两矩阵按列方向合并,要求行数相同,这里是加入了全为1的偏置项
boston_data_plus_bias = np.c_[np.ones((m, 1)), boston.data]

X = tf.constant(boston_data_plus_bias, dtype = tf.float32, name = 'X')
y = tf.constant(boston.target.reshape(-1, 1), dtype = tf.float32, name = 'y')
XT = tf.transpose(X)
#最小二乘法求解线性回归参数公式 θ = (XT·X)^-1·XT·y