<jupyter_start><jupyter_text>Simple Regression Example![photo_2019-11-17_12-30-33.jpg](attachment:photo_2019-11-17_12-30-33.jpg)<jupyter_code>import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

np.random.seed(101)
np.random.seed(101)

n_features = 10
n_dense_neuros = 3<jupyter_output><empty_output><jupyter_text>Create a random data<jupyter_code>_w_,_b_ = np.random.rand(2)
POINTS = 1000
MARGIN = 0.00001
def noising():
    return np.random.uniform(-1.5, 1.5, POINTS)

def teach_me(x):
    return _w_ * x + _b_
    
data = np.linspace(0,10,POINTS) + noising()
labels = np.linspace(0,10,POINTS) + noising()

plt.plot(data, labels, '*')
plt.plot(data, teach_me(data), 'r')

W = tf.Variable(_w_)
b = tf.Variable(_b_)    
error = 0
for d,l in zip(data, labels):
    l_hat = W*d + b
    error += (l-l_hat)**2
optimizer = tf.train.GradientDescentOptimizer(learning_rate=MARGIN)
train = optimizer.minimize(error)
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)
    training_steps = 1000
    for s in range(training_steps):
        sess.run(train)
    final_slope, final_intersept = sess.run([W,b])<jupyter_output><empty_output><jupyter_text>Testing<jupyter_code>data_test = np.linspace(-1,11,POINTS)
label_test = final_slope * data_test + final_intersept

plt.plot(data, labels, '*')
plt.plot(data, teach_me(data), 'r')
plt.plot(data_test, label_test, 'g')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1429548563611491, 'fraction_numerical': 0.04582763337893297, 'mean_word_length': 5.388646288209607, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '500021', 'license': 'MIT', 'n_tokens_mistral': 641, 'n_tokens_neox': 593, 'n_words': 103, 'path': 'TensorFlowUDemy/Solve regression problem using tensorflow.ipynb', 'repo_name': 'FyodorK/operation_cwal', 'size': '1462'}