diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2016-01-23 12:20:38 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2016-01-23 12:20:38 +0100 |
| commit | 66edd441607dacd42a2b71c2762a257b0ef5656f (patch) | |
| tree | 06f60e866340ed07e30b49bb0600b4122e4720ab | |
| download | boston-neuralnet-66edd441607dacd42a2b71c2762a257b0ef5656f.tar.gz boston-neuralnet-66edd441607dacd42a2b71c2762a257b0ef5656f.zip | |
geht nicht
| -rw-r--r-- | boston.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/boston.py b/boston.py new file mode 100644 index 0000000..55c814e --- /dev/null +++ b/boston.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 +from sklearn import datasets +from sklearn import preprocessing +from sklearn.cross_validation import train_test_split +import numpy as np +import tensorflow as tf + +dataset = datasets.load_boston() +data, target = dataset.data, dataset.target + +data_scaler = preprocessing.MinMaxScaler() +target_scaler = preprocessing.MinMaxScaler() + +data = data_scaler.fit_transform(data) +target = target_scaler.fit_transform(target) + +np.random.seed(0) + +x_train, x_test, y_train, y_test = train_test_split( + data, target, train_size=0.85 +) + + +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.add(tf.matmul(x, W), 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) + +init = tf.initialize_all_variables() +sess = tf.Session() +sess.run(init) + +last = 0 +batchsize = 50 +next_last = last + batchsize +while next_last < len(x_train): + print("running next batch") + next_last = last + batchsize + if 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}) + last = next_last + +print("finished training") + +diff = tf.sub(y, y_) +print(sess.run(diff, feed_dict={x: x_test, y_: y_test})) |
