<jupyter_start><jupyter_text>normalise x and y terms to fit for our Neural Network<jupyter_code>X1= train_set[:,1:257]
X2 = TestData[:,1:257]
X1 = X1 - X1.min() # normalize the values to bring them into the range 0-1
X2 = X2-X2.min() # normalize the values to bring them into the range 0-1
X1 = X1/X1.max()
X2 = X2/X2.max()
Y1 = train_set[:,0]
Y2 = TestData[:,0]
Y1 = (np.reshape(Y1, (len(Y1), 1)))
Y2 = (np.reshape(Y2, (len(Y2), 1)))
print(Y1.shape)
X1.shape
X2.shape<jupyter_output><empty_output><jupyter_text>Fine tuning such that target returns valid for 1 and invalid for other inputs<jupyter_code>for i in range(len(Y1)):
    if(Y1[i]|Y2[i] != 1):
        Y1[i],Y2[i] = -1
input_len = X1.shape[1]
L_NN = hiddenL(input_len)
for i in range(1,len(L_NN)-1):
  size = len(L_NN)-1
Wt_Neural = gen_weight(L_NN)
for i in range(len(Wt_Neural)):
    print("No of weights into Layer-",i+1,": ",Wt_Neural[i].shape)
print("Size of weight vector: ", len(Wt_Neural))
Err = []

for _ in range(2*(10**6)):
    Ein = 0
    gradient = 0
    G_Vector = []

    i = ran.randint(len(X1));
    for i in range(len(L_NN) - 1):
        G_Vector.append(0.0)
    
    Delout,sLNN,VNN = fwd_Propagation(Wt_Neural,X1[i],L_NN)
    predictedOutput = np.sign(DelOut)
    deltaLNN = 2 * (DelOut-Y1[i]) * actPrime(DelOut)
    Ein = Ein + (1/len(X1))* mean_squared_error(DelOut,Y1[i])
    G_Vector[0] = G_Vector[0] + ((1/len(X1)) * (np.dot(np.transpose(X1[i]),del_vector[len(back_Propagation(X1[i],Y1[i],DelOut,VNN,L_NN,deltaLNN))-1])))
    temp = []
    temp.append(X1)
    
    for i in range(len(VNN)-1):
        temp.append(VNN[i])
        
    for i in range(2,len(L_NN)-1):
        temp[i-1] = np.reshape(temp[i-1],(len(temp[i-1]),1))
        GLN = np.dot(del_vector[len(del_vector)-i], temp[i-1])
        G_Vector[i] = G_Vector[i] + ((1/len(X1)) * GLN[0][0])

    for i in range(len(Wt_Neural)):
        Wt_Neural[i] = Wt_Neural[i] - (0.01) *  G_Vector[i]
    Err.append(Ein)
import matplotlib.pyplot as plt
matplotlib inline
fig,ax = plt.subplots(figsize=(12,8))
ax.set_ylabel('Ein')
ax.set_xlabel('Iterations')
H = ax.plot(range(2*(10**6)),Err,'b.')<jupyter_output><empty_output><jupyter_text>formal test<jupyter_code>from sklearn.metrics import mean_squared_error
DelOutTt,sLTest,theta_VectorTest = fwd_Propagation(Wt_Neural,X2,L_NN)
T_Out = np.sign(DelOutTt)
errorTest = np.sqrt(mean_squared_error(Y2, T_Out))
print("predicted output: ",T_Out)<jupyter_output>predicted output:  [[-1.]
 [-1.]
 [-1.]
 ...
 [-1.]
 [-1.]
 [-1.]]
{'fraction_non_alphanumeric': 0.18555466879489227, 'fraction_numerical': 0.04389465283320032, 'mean_word_length': 4.169072164948454, 'pattern_counts': {'":': 1, '<': 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': '627197', 'license': 'MIT', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1124, 'n_words': 200, 'path': '013774228_HW4/all_parts_2_1_2_2_and_2_3.ipynb', 'repo_name': 'xlsarath/learning-from-the-data-Machine-learning-homework-solutions', 'size': '2506'}