In [2]:
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
c = tf.reduce_mean(a)
sesss=tf.Session()
sesss.run(c)
Out[2]:
In [3]:
import tensorflow as tf
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
d = tf.reduce_mean(b)
sesss=tf.Session()
sesss.run(d)
Out[3]:
In [6]:
#variance(x)=sum((x−mean(x))2)
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
c = tf.reduce_mean(a)
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
d = tf.reduce_mean(b)
e = a-c
f = e*e
g = tf.reduce_mean(f)*6
sesss=tf.Session()
sesss.run(g)
Out[6]:
In [15]:
#Covariance
#covariance=sum((x(i)−mean(x))∗(y(i)−mean(y)))
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
c = tf.reduce_mean(a)
b = tf.constant([2.0, 3.0, 4.0, 5.0, 6.0, 7.0])
d = tf.reduce_mean(b)
e = (a-c)*(b-d)
f = tf.reduce_mean(e)*6
sesss=tf.Session()
sesss.run(f)
Out[15]:
In [21]:
#m=covariance(x,y)/variance(x)
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
c = tf.reduce_mean(a)
b = tf.constant([7.0, 6.0, 5.0, 4.0, 8.0, 9.0])
d = tf.reduce_mean(b)
#Variance
e = a-c
f = e*e
var = tf.reduce_mean(f)*6
#Co-Variance
l = (a-c)*(b-d)
cov = tf.reduce_mean(l)*6
#m=covariance(x,y)/variance(x)
m=tf.div(cov,var)
sesss=tf.Session()
sesss.run(m)
Out[21]:
In [23]:
#c=mean(y)−m∗mean(x)
import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
c = tf.reduce_mean(a)
b = tf.constant([7.0, 6.0, 5.0, 4.0, 8.0, 9.0])
d = tf.reduce_mean(b)
#Variance
e = a-c
f = e*e
var = tf.reduce_mean(f)*6
#Co-Variance
l = (a-c)*(b-d)
cov = tf.reduce_mean(l)*6
#m=covariance(x,y)/variance(x)
m=tf.div(cov,var)
##c=mean(y)−m∗mean(x)
r = d-m*c
sesss=tf.Session()
sesss.run(r)
Out[23]:
In [27]:
import tensorflow as tf
tf.reset_default_graph()
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
b = tf.constant([7.0, 6.0, 5.0, 4.0, 8.0, 9.0])
with tf.name_scope("Mean_X_and_Y"):
with tf.name_scope("Mean_X"):
c = tf.reduce_mean(a)
with tf.name_scope("Mean_Y"):
d = tf.reduce_mean(b)
with tf.name_scope("Variance"):
e = a-c
f = e*e
var = tf.reduce_mean(f)*6
with tf.name_scope("Co-Variance"):
l = (a-c)*(b-d)
cov = tf.reduce_mean(l)*6
with tf.name_scope("M"):
m=tf.div(cov,var)
with tf.name_scope("C"):
r = d-m*c
with tf.Session() as sess:
writer = tf.summary.FileWriter("/tmp/tboard/output3", sess.graph)
print(sess.run(r))
writer.close()
In [ ]: