Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Perceptron and Simple Neural Network 1. Create a python file named myperceptron.py. Import the following packages. import numpy as np import matplotlib.pyplot as plt import

Perceptron and Simple Neural Network

1. Create a python file named myperceptron.py. Import the following packages.

import numpy as np

import matplotlib.pyplot as plt

import neurolab as nl

2. Load the data file and show the printout.

text = np.loadtxt('perceptron_data.txt')

# Separate datapoints and labels

data = text[:, :2]

labels = text[:, 2].reshape((text.shape[0], 1))

print(data)

print(labels)

3. Plot the data points and show the figure (Paste it below).

plt.figure()

plt.scatter(data[:,0], data[:,1])

plt.xlabel('Dimension 1')

plt.ylabel('Dimension 2')

plt.title('Input data')

plt.show()

4. Add the following lines to define the minimum and maximum values for each dimension. Show the printout.

# Define minimum and maximum values for each dimension

dim1_min, dim1_max, dim2_min, dim2_max = 0, 1, 0, 1

n_output = labels.shape[1]

print(n_output)

5. Add the following lines. Explain what the method nl.net.newp do?

D1 = [dim1_min, dim1_max]

D2 = [dim2_min, dim2_max]

perceptron = nl.net.newp([D1, D2], n_output)

6. Add the following lines. (1) Explain what the method perceptron.train do? (2) Explain what the meaning of each parameter is?

error_progress = perceptron.train(data, labels, epochs=4, lr=0.01)

7. Add the following lines and show the figure (paste it below).

plt.figure()

plt.plot(error_progress)

plt.xlabel('epochs')

plt.ylabel('Training error')

plt.title('Training progress')

plt.grid()

plt.show()

8. Create a new python file named myfirstnn.py. Import the following libraries.

import numpy as np

import matplotlib.pyplot as plt

import neurolab as nl

9. Load the data file by adding the following lines. Show the printout.

text = np.loadtxt('first_nn_data.txt')

data = text[:, 0:2]

labels = text[:, 2:]

print(data)

print(labels)

10. Add the following lines. Show the printout.

D1 = [data[:,0].min(), data[:,0].max()]

D2 = [data[:,1].min(), data[:,1].max()]

n_output = labels.shape[1]

print(n_output)

11. Add the following lines. Show the figure.

nn = nl.net.newp([D1, D2], n_output)

error_progress = nn.train(data, labels, epochs=50, lr=0.02)

plt.figure()

plt.plot(error_progress)

plt.xlabel('Epochs')

plt.ylabel('Training error')

plt.title('Training progress')

plt.grid()

plt.show()

12. Add the following lines. (1) Show the printout. (2) what is the meaning of the printout?

test = [[0.5, 4.5], [4.0, 0.5], [4.5, 8.2]]

for t in test:

print(t, '-->', nn.sim([t])[0])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students explore these related Databases questions