0% found this document useful (0 votes)
15 views

NNDL-Lab Test(033)

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

NNDL-Lab Test(033)

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Code for Single Layer Perceptron:-

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
x=np.array([[1.0],[2.0],[3.0],[4.0]],dtype=np.float32)
y=np.array([[0.0],[-1.0],[-2.0],[-3.0]],dtype=np.float32)
model=Sequential()
model.add(Dense(1,input_shape=(1,),activation='linear'))
model.compile(optimizer='sgd',loss='mean_squared_error')
history=model.fit(x,y,epochs=10,verbose=2)
predictions=model.predict(x)
print("predictions")
print(predictions)

Code for Multi Layer Perceptron:-

import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

x = np.array([[1.0], [2.0], [3.0], [4.0]], dtype=np.float32)


y = np.array([[0.0], [-1.0], [-2.0], [-3.0]], dtype=np.float32)
model = Sequential()
model.add(Dense(64, input_shape=(1,), activation='relu'))
model.add(Dense(32, activation='relu'))
model.add(Dense(1, activation='linear'))
model.compile(optimizer='sgd', loss='mean_squared_error')
history = model.fit(x, y, epochs=10, verbose=2)
predictions = model.predict(x)
print("predictions")
print(predictions)

You might also like