This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def power(x, n): | |
""" | |
Compute the value x n for integer n | |
""" | |
if n == 0: | |
return 1 | |
else: | |
partial = power(x, n // 2) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
x = tf.constant(10) | |
y = tf.constant(2) | |
z = tf.subtract(tf.divide(x,y),tf.cast(tf.constant(1), tf.float64)) | |
with tf.Session() as sess: | |
output = sess.run(z) | |
print(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
x = tf.placeholder(tf.string) | |
y = tf.placeholder(tf.int32) | |
z = tf.placeholder(tf.float32) | |
with tf.Session() as sess: | |
output = sess.run(x, feed_dict={x: 'Test String', y: 123, z: 45.67}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
x = tf.placeholder(tf.string) | |
with tf.Session() as sess: | |
output = sess.run(x, feed_dict={x: 'Hello World'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
# You can create constants in TF to hold specific values | |
a = tf.constant(1) | |
b = tf.constant(2) | |
A = tf.constant(1234) | |
# B is a 1-dimensional int32 tensor | |
B = tf.constant([123,456,789]) | |
# C is a 2-dimensional int32 tensor | |
C = tf.constant([ [123,456,789], [222,333,444] ]) | |
# Adding and multiplying the constants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with tf.Session() as sess: | |
sess.run(init) | |
display_step = 20 | |
# Fit all training data | |
for iteration in range(training_iteration): | |
# Run the gradient descent optimizer | |
sess.run(optimizer, feed_dict={X: X_train, Y: Y_train}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_cost_optimizer_tensor(Y, model, size, learning_rate): | |
""" | |
Tensor for calculating the cost function and the the optimizer for | |
minimizing the cost. | |
""" | |
# Cost function tensor. | |
cost_function = tf.reduce_sum(tf.pow(model - Y, 2))/(2 * size) | |
# gradient descent tensor. | |
gradient_descent = tf.train.GradientDescentOptimizer(learning_rate) | |
# optimization tensor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_model_tensors(): | |
""" | |
function obtain model tensor | |
""" | |
# X is the placeholder for size of the house from the dataset. | |
# Y is the placeholder for size of the house from the dataset. | |
X = tf.placeholder("float") | |
Y = tf.placeholder("float") | |
# The parameters theta0 and theta1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
# import library to split the data | |
from sklearn.model_selection import train_test_split | |
%matplotlib inline | |
import matplotlib.pyplot as plt | |
def read_data(): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:2.7 | |
MAINTAINER Karthic Rao "[email protected]" | |
COPY . /app | |
WORKDIR /app | |
RUN pip install -r requirements.txt | |
ENTRYPOINT ["python"] | |
CMD ["app.py"] |