<jupyter_start><jupyter_text>Import<jupyter_code>import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Plot on graph<jupyter_code>X = np.array( [[4.5,35], [4.9,38], [5.0,45], [4.8,49], [5.8,59], [5.6,65], [5.7, 73], [5.8,82]] )
Y = np.array( [[-1], [-1], [-1], [-1], [1], [1], [1], [1], ] )

plt.figure()
for index, x in enumerate(X):
    if Y[index] ==-1:
        plt.scatter(x[0],x[1],c='m',marker='o')
    else:
        plt.scatter(x[0],x[1],c='r',marker='x')
plt.xlabel("Height")
plt.ylabel("Weight")
plt.show()<jupyter_output><empty_output><jupyter_text>Activation function<jupyter_code>def activation(z):
    if z<0:
        return -1
    else:
        return 1<jupyter_output><empty_output><jupyter_text>Perceptron training model<jupyter_code>np.hstack( (np.ones((8, 1)), X) )
np.random.rand(7+1).reshape((-1,1))
def perceptron(X, Y, learning_rate):
    num_samples, num_features = X.shape 
    X = np.hstack( (np.ones((num_samples, 1)), X) ) #Input data + bias
    W = np.random.rand(num_features+1).reshape((-1,1)) #Random weights 
    sample_misclassified = True
    while sample_misclassified:
        sample_misclassified = False    
        for index, x in enumerate(X):
            if activation(x.reshape((1,-1))@W) != Y[index]: 
                samples_misclassified = True
                W = W + Y[index] * learning_rate * x.reshape((-1,1)) # Gradient Descent 
    return W<jupyter_output><empty_output><jupyter_text>Test<jupyter_code>learning_rate = 0.1
W = perceptron(X,Y,0.1) 
plt.figure()
plt.plot([4.4,6],[90,40],linewidth=1,label="Decision_boundary")
for index, x in enumerate(X):
    if Y[index] == -1:
        plt.scatter(x[0],x[1],c='b',marker = 'o')
    else:
        plt.scatter(x[0],x[1],c='g',marker = 'x')
plt.legend(loc="best")
plt.xlabel("Height")
plt.ylabel("Weight");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.199679658302189, 'fraction_numerical': 0.04217832354511479, 'mean_word_length': 4.106267029972752, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '651724', 'license': 'MIT', 'n_tokens_mistral': 809, 'n_tokens_neox': 761, 'n_words': 125, 'path': 'Perceptron Learning Model.ipynb', 'repo_name': 'AnshDesai/Neural-Networks', 'size': '1873'}