0% found this document useful (0 votes)
13 views2 pages

06/11/24, 10 02 AM Page 41 of 56

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

06/11/24, 10 02 AM Page 41 of 56

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exp 10

import numpy as np

input_data = np.array([[1, 0, 1, 0], [1, 0, 1, 1], [0, 1, 0, 1]])


output_data = np.array([[1], [1], [0]])

def sigmoid(x):
return 1 / (1 + np.exp(-x))

def sigmoid_derivative(x):
return x * (1 - x)

epochs = 5000
learning_rate = 0.1

input_neurons = input_data.shape[1]
hidden_neurons = 3
output_neurons = 1

https://colab.research.google.com/drive/13oTpQmuxdl-qr9HHkOClyK7IY5L-laNc#scrollTo=WVG8_Jx4OPEy 06/11/24, 10 02 AM
Page 41 of 56
:
weights_input_hidden = np.random.uniform(size=(input_neurons, hidden_neurons))
bias_hidden = np.random.uniform(size=(1, hidden_neurons))
weights_hidden_output = np.random.uniform(size=(hidden_neurons, output_neurons))
bias_output = np.random.uniform(size=(1, output_neurons))

for epoch in range(epochs):


hidden_layer_input = np.dot(input_data, weights_input_hidden) + bias_hidden
hidden_layer_output = sigmoid(hidden_layer_input)
output_layer_input = np.dot(hidden_layer_output, weights_hidden_output) + bi
predicted_output = sigmoid(output_layer_input)

error_output_layer = output_data - predicted_output


slope_output_layer = sigmoid_derivative(predicted_output)
slope_hidden_layer = sigmoid_derivative(hidden_layer_output)

delta_output_layer = error_output_layer * slope_output_layer


error_hidden_layer = delta_output_layer.dot(weights_hidden_output.T)
delta_hidden_layer = error_hidden_layer * slope_hidden_layer

weights_hidden_output += hidden_layer_output.T.dot(delta_output_layer) * lea


weights_input_hidden += input_data.T.dot(delta_hidden_layer) * learning_rate
bias_output += np.sum(delta_output_layer, axis=0, keepdims=True) * learning_
bias_hidden += np.sum(delta_hidden_layer, axis=0, keepdims=True) * learning_

print("Predicted output after training:")


print(predicted_output)

Predicted output after training:


[[0.9831553 ]
[0.96735236]
[0.04442678]]

Exp 11

import itertools
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import PassiveAggressiveClassifier
from sklearn.metrics import accuracy_score, confusion_matrix

df = pd.read_csv("cancerdata.csv")

https://colab.research.google.com/drive/13oTpQmuxdl-qr9HHkOClyK7IY5L-laNc#scrollTo=WVG8_Jx4OPEy 06/11/24, 10 02 AM
Page 42 of 56
:

You might also like