<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Regression<jupyter_code>X = np.array([[1,2,3],[3,4,5],[5,6,7],[7,8,9],[9,8,7]])
Y = np.array([1,2,3,4,5])
             
print(X.shape)
print(Y.shape)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X[:,0], X[:,1], X[:,2], c='r', marker='o')<jupyter_output><empty_output><jupyter_text>Hyperparameters & Parameters<jupyter_code>no_of_inputs = X.shape[1]
epochs = 50
learning_rate = .01
weights = np.random.rand(no_of_inputs + 1)
print(weights.shape)<jupyter_output>(4,)<jupyter_text>Activation Function<jupyter_code>def relu_activation(sum):
  if sum > 0: return sum
  else: return 0<jupyter_output><empty_output><jupyter_text>Step Activation The Preceptron Class<jupyter_code>class Perceptron(object):
  def __init__(self, no_of_inputs, activation):
    self.learning_rate = learning_rate
    self.weights = np.zeros(no_of_inputs + 1)
    self.activation = activation
           
  def predict(self, inputs):
    summation = np.dot(inputs, self.weights[1:]) + self.weights[0]
    return self.activation(summation)

  def train(self, training_inputs, training_labels, epochs=100, learning_rate=0.01):
    history = []
    for _ in range(epochs):
      for inputs, label in zip(training_inputs, training_labels):
        prediction = self.predict(inputs)
        loss = (label - prediction) 
        loss2 = loss*loss
        history.append(loss2)
        print(f"loss = {loss2}")
        self.weights[1:] += self.learning_rate * loss * inputs
        self.weights[0] += self.learning_rate * loss
    return history<jupyter_output><empty_output><jupyter_text>Regression Perceptron & Training<jupyter_code>perceptron = Perceptron(no_of_inputs, relu_activation)
history = perceptron.train(X,Y, epochs=epochs)<jupyter_output>loss = 1
loss = 2.9929
loss = 1.72265625
loss = 0.02312680562499999
loss = 1.6902294577880648
loss = 0.43885090318244224
loss = 1.0864744810899838
loss = 0.5473581787468343
loss = 0.014073938663058378
loss = 0.806173118252477
loss = 0.226218111111116
loss = 0.6366065678544175
loss = 0.35172612685266824
loss = 0.005872910287421307
loss = 0.6893285923774122
loss = 0.14966337430831014
loss = 0.49888973542955645
loss = 0.30699091008926555
loss = 0.002750120538693394
loss = 0.5718974980242251
loss = 0.09254885825287329
loss = 0.382854052289803
loss = 0.26507499379402366
loss = 0.0009190407225200681
loss = 0.4770785550003508
loss = 0.053279506555312314
loss = 0.29258492422220883
loss = 0.23034143290479603
loss = 0.00011403726147022208
loss = 0.3995448559617547
loss = 0.02739320083670002
loss = 0.22228179185201707
loss = 0.2012886594034766
loss = 4.578433319278737e-05
loss = 0.33603928207373074
loss = 0.011537968868818983
loss = 0.16771798370408128
loss = 0.17691666672060313
loss = 0.00049524[...]<jupyter_text>Regression Prediction<jupyter_code>perceptron.predict(np.array([3,3,3]))
plt.plot(history)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12152317880794702, 'fraction_numerical': 0.2324503311258278, 'mean_word_length': 5.455128205128205, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '169565', 'license': 'Apache-2.0', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1198, 'n_words': 189, 'path': 'GEN_1_perceptron_class.ipynb', 'repo_name': 'cxbxmxcx/GenReality', 'size': '3020'}