<jupyter_start><jupyter_text>In this notebook, we'll try create a neural network that performs a very simple linear fit to some 2D data.Below given is the "Graph of wX + b = z" : ![Screenshot%202018-12-22%20at%203.17.33%20PM.png](attachment:Screenshot%202018-12-22%20at%203.17.33%20PM.png) Once we build the above network, we'll also introduce some sort of optimization function that tunes 'w' and 'b'.<jupyter_code>#Set seeds to ensure same results
np.random.seed(101)
tf.set_random_seed(101)
#Building our random dummy data
rand_a = np.random.uniform(0, 100, size=(5, 5))
rand_a
rand_b = np.random.uniform(0, 100, size=(5, 1))
rand_b
n_features = 10
n_dense_neurons = 3
x = tf.placeholder(tf.float32, (None, n_features))

W = tf.Variable(initial_value=tf.random_uniform((n_features, n_dense_neurons)))
b = tf.Variable(initial_value=tf.ones((n_dense_neurons)))
xW = tf.matmul(x, W)
z = tf.add(xW, b)

a = tf.sigmoid(z)
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)
    layer_outputs = sess.run(a, feed_dict={x:np.random.random((1, n_features))})
print(layer_outputs)<jupyter_output>[[0.97186095 0.9830446  0.9802405 ]]<jupyter_text>Simple Regression example<jupyter_code>x_data = np.linspace(0, 10, 10) + np.random.uniform(-1.5, 1.5, 10)   # Add some noise to our dummy input data
x_data
y_labels = np.linspace(0, 10, 10) + np.random.uniform(-1.5, 1.5, 10)
y_labels
plt.plot(x_data, y_labels, '*')<jupyter_output><empty_output><jupyter_text>y = mX + b<jupyter_code>np.random.rand(2)
m = tf.Variable(initial_value=0.44)
b = tf.Variable(initial_value=0.87)
# Optimize using the cost function
error = 0 # Initial error

for x, y in zip(x_data, y_labels):
    y_hat = m * x + b
    
    error = (y - y_hat)**2   # Cost function
# Gradient descent Optimizer
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
train = optimizer.minimize(error)   # Tell the optimizer what it actually needs to minimize
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)
    
    iterations = 15
    for i in range(iterations):
        sess.run(train)

    final_slope, final_intercept = sess.run([m, b])
x_test = np.linspace(-1, 11, 10)
predictions = final_slope * x_test + final_intercept

plt.plot(x_data, y_labels, '*')
plt.plot(x_test, predictions)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13344666383340417, 'fraction_numerical': 0.05694857628559286, 'mean_word_length': 5.051413881748072, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '305161', 'license': 'MIT', 'n_tokens_mistral': 996, 'n_tokens_neox': 894, 'n_words': 212, 'path': 'Lesson-2. Basic Neural Network using Tensorflow.ipynb', 'repo_name': 'ramapinnimty/Hands-on-Tensorflow', 'size': '2353'}