diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2016-01-23 16:31:33 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2016-01-23 16:31:33 +0100 |
| commit | bd2f24c0924986498bcbf1655ac0bbbb7fb1eb24 (patch) | |
| tree | be8645ea65368a23e2141653e305d280cf6ae7c1 | |
| parent | 66edd441607dacd42a2b71c2762a257b0ef5656f (diff) | |
| download | boston-neuralnet-bd2f24c0924986498bcbf1655ac0bbbb7fb1eb24.tar.gz boston-neuralnet-bd2f24c0924986498bcbf1655ac0bbbb7fb1eb24.zip | |
checkpoint
| -rw-r--r-- | boston.py | 58 |
1 files changed, 44 insertions, 14 deletions
@@ -11,29 +11,52 @@ data, target = dataset.data, dataset.target data_scaler = preprocessing.MinMaxScaler() target_scaler = preprocessing.MinMaxScaler() +print(target) data = data_scaler.fit_transform(data) target = target_scaler.fit_transform(target) +target_scale = [target_scaler.inverse_transform([1])] # TODO hack +target_offset = [target_scaler.inverse_transform([0])] + np.random.seed(0) x_train, x_test, y_train, y_test = train_test_split( - data, target, train_size=0.85 + data, target, train_size=0.8 ) +sess = tf.InteractiveSession() + x = tf.placeholder(tf.float32, [None, 13], name="input") -W = tf.Variable(tf.zeros([13, 1]), name="weight") -b = tf.Variable(tf.zeros([1]), name="bias") +y_ = tf.placeholder(tf.float32, [1, None], name="target") +tscal = tf.placeholder(tf.float32, [1, 1], name="scaler") +toffs = tf.placeholder(tf.float32, [1, 1], name="offset") + +W = tf.Variable(tf.zeros([13]), name="weight") +b = tf.Variable(0.0, name="bias") + +sess.run(tf.initialize_all_variables()) -y = tf.add(tf.matmul(x, W), b) +weighted = tf.mul(x, W) +combined_weights = tf.reduce_sum(weighted, 1) +y = tf.nn.sigmoid(tf.add(combined_weights, b)) -y_ = tf.placeholder(tf.float32, name="target") -rmsle = tf.reduce_mean(tf.sqrt(tf.log(y_) - tf.log(y))) -train_step = tf.train.GradientDescentOptimizer(0.1).minimize(rmsle) +tscal = tf.transpose(tscal) -init = tf.initialize_all_variables() -sess = tf.Session() -sess.run(init) +scaled_y = tf.add(tf.mul(y, tscal), toffs) +scaled_y_ = tf.add(tf.mul(y_, tscal), toffs) + +foo = tf.add(y_, 0) +foo = tf.Print(foo, [foo], "y_: ") +scaled_y_ = tf.Print(scaled_y_, [scaled_y_], "scaled_y_: ") +scaled_y = tf.add(scaled_y, foo) # delme + +diff = tf.square(tf.sub(tf.log(scaled_y + 1), tf.log(scaled_y_ + 1))) +mean = tf.reduce_mean(diff) +sqrt = tf.sqrt(mean) +rmsle = tf.reduce_mean(sqrt) + +train_step = tf.train.GradientDescentOptimizer(0.01).minimize(rmsle) last = 0 batchsize = 50 @@ -45,11 +68,18 @@ while next_last < len(x_train): next_last = len(x_train) xt = x_train[last:next_last] - yt = y_train[last:next_last] - sess.run(train_step, feed_dict={x: xt, y_: yt}) + yt = [y_train[last:next_last]] #[[_] for _ in y_train[last:next_last]] + + print("yt " + str(yt[0:3])) + print("tsc " + str(target_scaler.inverse_transform(yt[0:3]))) + print("calc " + str([el * target_scale + target_offset for el in yt[0:3]])) + sess.run(train_step, feed_dict={x: xt, y_: yt, tscal: target_scale, toffs: target_offset}) last = next_last print("finished training") -diff = tf.sub(y, y_) -print(sess.run(diff, feed_dict={x: x_test, y_: y_test})) +#diff = tf.reduce_mean(tf.sub(scaled_y, scaled_y_)) +yt = [y_test] +print(" --------- ") +print("mean difference to test data: ") +print(sess.run(rmsle, feed_dict={x: x_test, y_: yt, tscal: target_scale, toffs: target_offset})) |
