In [33]:
#USN:01FE15BCS237
#Roll:244
#lAB2_Assignment_1

import tensorflow as tf
x=tf.constant([1.1,2.2,3.3,4.4])
y=tf.constant([2.2,3.3,4.4,5.5])

mean_x=tf.reduce_mean(x)
mean_y=tf.reduce_mean(y)

ss=tf.Session()
print (ss.run(mean_x))
print (ss.run(mean_y))


x_x=tf.subtract(x,mean_x)


y_y=tf.subtract(y,mean_y)


sqr1=tf.square(x_x)

sqr2=tf.square(y_y)


var1=tf.reduce_sum(sqr1)

var2=tf.reduce_sum(sqr2)

print (ss.run(var1))

print (ss.run(var2))

tmp=tf.multiply(x_x,y_y)
cov=tf.reduce_sum(tmp)
print (ss.run(cov))


m=tf.div(cov,var1)
print (ss.run(m))

tmp2=tf.multiply(m,mean_x)
c=tf.subtract(mean_y,tmp2)
print (ss.run(c))


#Estimate y using y=mx+c
for c in range(1,10):
    for m in range(1,10):
        prdcted_y=tf.add(tf.multiply(x,m),c)
        print (ss.run(prdcted_y))
        #Finding RMS ERROR for different values of m and c
        rms = tf.div(tf.sqrt(tf.reduce_mean(tf.squared_difference(prdcted_y, y))),tf.to_float(tf.size(x)))
        print(ss.run(rms))


2.75
3.85
6.05
6.05
6.05
1.0
1.1
[ 2.0999999   3.20000005  4.30000019  5.4000001 ]
0.025
[ 3.20000005  5.4000001   7.5999999   9.80000019]
0.730368
[  4.30000019   7.60000038  10.89999962  14.20000076]
1.48345
[  5.4000001    9.80000019  14.19999981  18.60000038]
2.23656
[  6.5  12.   17.5  23. ]
2.98967
[  7.60000038  14.20000076  20.79999924  27.40000153]
3.74278
[  8.70000076  16.40000153  24.10000038  31.80000114]
4.4959
[  9.80000019  18.60000038  27.39999962  36.20000076]
5.24902
[ 10.90000057  20.80000114  30.69999886  40.60000229]
6.00214
[ 3.0999999   4.19999981  5.30000019  6.4000001 ]
0.225
[  4.19999981   6.4000001    8.60000038  10.80000019]
0.962906
[  5.30000019   8.60000038  11.89999962  15.20000076]
1.7141
[  6.4000001   10.80000019  15.19999981  19.60000038]
2.46646
[  7.5  13.   18.5  24. ]
3.21918
[  8.60000038  15.20000076  21.79999924  28.40000153]
3.97205
[  9.70000076  17.40000153  25.10000038  32.80000305]
4.725
[ 10.80000019  19.60000038  28.39999962  37.20000076]
5.478
[ 11.90000057  21.80000114  31.69999886  41.60000229]
6.23102
[ 4.0999999   5.19999981  6.30000019  7.4000001 ]
0.475
[  5.19999981   7.4000001    9.60000038  11.80000019]
1.20247
[  6.30000019   9.60000038  12.89999962  16.20000076]
1.94952
[  7.4000001   11.80000019  16.20000076  20.60000038]
2.69994
[  8.5  14.   19.5  25. ]
3.45154
[  9.60000038  16.20000076  22.79999924  29.40000153]
4.20368
[ 10.70000076  18.40000153  26.10000038  33.80000305]
4.95612
[ 11.80000019  20.60000038  29.39999962  38.20000076]
5.70874
[ 12.90000057  22.80000114  32.69999695  42.60000229]
6.46147
[ 5.0999999   6.19999981  7.30000019  8.39999962]
0.725
[  6.19999981   8.39999962  10.60000038  12.80000019]
1.44558
[  7.30000019  10.60000038  13.89999962  17.20000076]
2.18818
[  8.39999962  12.80000019  17.20000076  21.60000038]
2.93614
[  9.5  15.   20.5  26. ]
3.68621
[ 10.60000038  17.20000076  23.79999924  30.40000153]
4.43731
[ 11.70000076  19.40000153  27.10000038  34.80000305]
5.18899
[ 12.80000019  21.60000038  30.39999962  39.20000076]
5.94104
[ 13.90000057  23.80000114  33.69999695  43.60000229]
6.69333
[ 6.0999999   7.19999981  8.30000019  9.39999962]
0.975
[  7.19999981   9.39999962  11.60000038  13.80000019]
1.69069
[  8.30000019  11.60000038  14.89999962  18.20000076]
2.42912
[  9.39999962  13.80000019  18.20000076  22.60000038]
3.17446
[ 10.5  16.   21.5  27. ]
3.92277
[ 11.60000038  18.20000076  24.79999924  31.40000153]
4.67263
[ 12.70000076  20.40000153  28.10000038  35.80000305]
5.42339
[ 13.80000019  22.60000038  31.39999962  40.20000076]
6.17472
[ 14.90000057  24.80000114  34.69999695  44.60000229]
6.92644
[  7.0999999    8.19999981   9.30000019  10.39999962]
1.225
[  8.19999981  10.39999962  12.60000038  14.80000019]
1.93706
[  9.30000019  12.60000038  15.89999962  19.20000076]
2.67173
[ 10.39999962  14.80000019  19.20000076  23.60000038]
3.41445
[ 11.5  17.   22.5  28. ]
4.1609
[ 12.60000038  19.20000076  25.79999924  32.40000153]
4.9094
[ 13.70000076  21.40000153  29.10000038  36.80000305]
5.65912
[ 14.80000019  23.60000038  32.40000153  41.20000076]
6.40964
[ 15.90000057  25.80000114  35.69999695  45.60000229]
7.1607
[  8.10000038   9.19999981  10.30000019  11.39999962]
1.475
[  9.19999981  11.39999962  13.60000038  15.80000019]
2.18425
[ 10.30000019  13.60000038  16.89999962  20.20000076]
2.91558
[ 11.39999962  15.80000019  20.20000076  24.60000038]
3.65577
[ 12.5  18.   23.5  29. ]
4.40035
[ 13.60000038  20.20000076  26.79999924  33.40000153]
5.14742
[ 14.70000076  22.40000153  30.10000038  37.80000305]
5.89603
[ 15.80000019  24.60000038  33.40000153  42.20000076]
6.64565
[ 16.90000153  26.80000114  36.69999695  46.60000229]
7.39599
[  9.10000038  10.19999981  11.30000019  12.39999962]
1.725
[ 10.19999981  12.39999962  14.60000038  16.79999924]
2.43201
[ 11.30000019  14.60000038  17.89999962  21.20000076]
3.1604
[ 12.39999962  16.79999924  21.20000076  25.60000038]
3.8982
[ 13.5  19.   24.5  30. ]
4.64092
[ 14.60000038  21.20000076  27.79999924  34.40000153]
5.38653
[ 15.70000076  23.40000153  31.10000038  38.80000305]
6.13397
[ 16.79999924  25.60000038  34.40000153  43.20000076]
6.88266
[ 17.90000153  27.80000114  37.69999695  47.60000229]
7.63221
[ 10.10000038  11.19999981  12.30000019  13.39999962]
1.975
[ 11.19999981  13.39999962  15.60000038  17.79999924]
2.68019
[ 12.30000019  15.60000038  18.89999962  22.20000076]
3.40597
[ 13.39999962  17.79999924  22.20000076  26.60000038]
4.14152
[ 14.5  20.   25.5  31. ]
4.88243
[ 15.60000038  22.20000076  28.79999924  35.40000153]
5.62658
[ 16.70000076  24.40000153  32.09999847  39.80000305]
6.37284
[ 17.79999924  26.60000038  35.40000153  44.20000076]
7.12055
[ 18.90000153  28.80000114  38.69999695  48.60000229]
7.86928

In [ ]:


In [ ]:


In [ ]: