<jupyter_start><jupyter_text>First Neurons<jupyter_code>import numpy as np
import tensorflow as tf<jupyter_output><empty_output><jupyter_text>** Set Random Seeds for same results **<jupyter_code>np.random.seed(101)
tf.set_random_seed(101)<jupyter_output><empty_output><jupyter_text>** Data Setup ** Setting Up some Random Data for Demonstration Purposes<jupyter_code>rand_a = np.random.uniform(0,100,(5,5))
rand_a
rand_b = np.random.uniform(0,100,(5,1))
rand_b
# CONFIRM SAME  RANDOM NUMBERS (EXECUTE SEED IN SAME CELL!) Watch video for explanation
np.random.seed(101)
rand_a = np.random.uniform(0,100,(5,5))
rand_b = np.random.uniform(0,100,(5,1))<jupyter_output><empty_output><jupyter_text>Placeholders<jupyter_code>a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)<jupyter_output><empty_output><jupyter_text>Operations<jupyter_code>add_op = a+b # tf.add(a,b)
mult_op = a*b #tf.multiply(a,b)<jupyter_output><empty_output><jupyter_text>Running Sessions  to create Graphs with Feed Dictionaries<jupyter_code>with tf.Session() as sess:
ft<jupyter_output>[[ 151.07165527  156.49855042  102.27921295  116.58396149  167.95948792]
 [ 135.45622253   82.76316071  141.42784119  124.22093201   71.06043243]
 [ 113.30171204   93.09214783   76.06819153  136.43911743  154.42727661]
 [  96.7172699    81.83804321  133.83674622  146.38117981  101.10578918]
 [ 122.72680664  105.98292542   59.04463196   67.98310089   72.89292145]]


[[ 5134.64404297  5674.25         283.12432861  1705.47070312
   6813.83154297]
 [ 4341.8125      1598.26696777  4652.73388672  3756.8293457    988.9463501 ]
 [ 3207.8112793   2038.10290527  1052.77416992  4546.98046875
   5588.11572266]
 [ 1707.37902832   614.02526855  4434.98876953  5356.77734375
   2029.85546875]
 [ 3714.09838867  2806.64379883   262.76763916   747.19854736
   1013.29199219]]<jupyter_text>________________________________________________  Example Neural Network<jupyter_code>n_features = 10
n_dense_neurons = 3
# Placeholder for x
x = tf.placeholder(tf.float32,(None,n_features))
# Variables for w and b
b = tf.Variable(tf.zeros([n_dense_neurons]))

W = tf.Variable(tf.random_normal([n_features,n_dense_neurons]))<jupyter_output><empty_output><jupyter_text>** Operation Activation Function **<jupyter_code>xW = tf.matmul(x,W)
z = tf.add(xW,b)
# tf.nn.relu() or tf.tanh()
a = tf.sigmoid(z)<jupyter_output><empty_output><jupyter_text>** Variable Intializer! **<jupyter_code>init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)
    
    layer_out = sess.run(a,feed_dict={x : np.random.random([1,n_features])})
print(layer_out)<jupyter_output>[[ 0.63504547  0.48962751  0.98692095]]<jupyter_text>We still need to finish off this process with optimization! Let's learn how to do this next._____  Full Network ExampleLet's work on a regression example, we are trying to solve a very simple equation:y = mx + by will be the y_labels and x is the x_data. We are trying to figure out the slope and the intercept for the line that best fits our data!  Artifical Data (Some Made Up Regression Data)<jupyter_code>x_data = np.linspace(0,10,10) + np.random.uniform(-1.5,1.5,10)
x_data
y_label = np.linspace(0,10,10) + np.random.uniform(-1.5,1.5,10)
plt.plot(x_data,y_label,'*')<jupyter_output><empty_output><jupyter_text>** Variables **<jupyter_code>np.random.rand(2)
m = tf.Variable(0.39) f
b = tf.Variable(0.2)<jupyter_output><empty_output><jupyter_text>Cost Function<jupyter_code>error = 0

for x,y in zip(x_data,y_label):
    
    y_hat = m*x + b  #Our predicted value
    
    error += (y-y_hat)**2 # The cost we want to minimize (we'll need to use an optimization function for the minimization!)<jupyter_output><empty_output><jupyter_text>Optimizer<jupyter_code>optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
train = optimizer.minimize(error)<jupyter_output><empty_output><jupyter_text>Initialize Variables<jupyter_code>init = tf.global_variables_initializer()<jupyter_output><empty_output><jupyter_text>Create Session and Run!<jupyter_code>with tf.Session() as sess:
    
    sess.run(init)
    
    epochs = 100
    
    for i in range(epochs):
        
        sess.run(train)
        

    # Fetch Back Results
    final_slope , final_intercept = sess.run([m,b])
final_slope
final_intercept<jupyter_output><empty_output><jupyter_text>Evaluate Results<jupyter_code>x_test = np.linspace(-1,11,10)
y_pred_plot = final_slope*x_test + final_intercept

plt.plot(x_test,y_pred_plot,'r')

plt.plot(x_data,y_label,'*')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12013201320132014, 'fraction_numerical': 0.144994499449945, 'mean_word_length': 5.597968069666183, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '24221', 'license': 'MIT', 'n_tokens_mistral': 2205, 'n_tokens_neox': 1805, 'n_words': 315, 'path': 'study_python/tensorflow/Tensorflow-Bootcamp-master/02-TensorFlow-Basics/03-TF-Neural-Network.ipynb', 'repo_name': 'AlphaSunny/study', 'size': '4545'}