Files
regressions/linear_regression3.py
2018-08-16 18:16:27 +09:00

42 lines
794 B
Python

import numpy as np
import pandas as pd
import utility
df = utility.load_data()
y_data = df.values[:, 0]
x_data = df.values[:, 1:]
m, n = x_data.shape
import tensorflow as tf
y = tf.Variable(y_data)
x = tf.Variable(x_data)
w = tf.Variable(tf.zeros((n, 1)))
a = 0.1
#h = tf.matmul(x, w)
#cost = tf.reduce_mean(tf.square(h - y))
#optimizer = tf.train.GradientDescentOptimizer(a)
#train = optimizer.minimize(cost)
a = tf.Variable([[1], [2], [3]])
b = tf.Variable([1,2,3])
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
#k = sess.run(a*b)
#kk = sess.run(b*a)
##kkk = sess.run(tf.matmul(a, b))
#kkkk = sess.run(tf.matmul(b, a))
h = tf.matmul(x, w)
cost = tf.reduce_mean((h-y)**2)/2
gradient = (h-y)*x
values = sess.run((h, cost, gradient))
print(values)