Professional Documents
Culture Documents
Assignment II (20 %)
Instructor: Dr. Juhaida Abu Bakar
Submission date: 14th November 2020
Instruction: Answer all questions and submit your answers via UUM Online Learning Portal before
11.59 pm –14th November 2020.
This assignment will require you to implement and interpret some of the data analytics concepts that were
introduced in class using both Python programming language and KNIME toolkits. Keep in mind that the main
objective of this assignment is to highlight the insights that we can derive from applying these techniques—the
coding aspect is secondary. Accordingly, you are welcome to consult any online documentation and/or code
that has been posted to the course website, so long as all references and sources are properly cited.
Part A (Manual & Python Programming):
A group of UUM lecturers have an intention to develop a system that can predict whether a UUM’s graduate that has
completed their undergraduate study will be offered a job, continue their study or received no jobs offer. An example of
the collected data is Table 1 given below.
Table 1
Matric Gender Status EntryQualification CGPA English
level
22619 Male Working Matriculation 3.67 Good
22417 Female Further STPM 3.00 Moderate
Study
22353 Female Unemployed STPM 3.10 Poor
22456 Male Further Diploma 2.45 Poor
Study
33451 Female Working STPM 2.51 Good
Using the following techniques, find the most appropriate decision for these new cases.
2) Case Based Reasoning (assuming all attributes are equally important and ∑ w=1) and the
highest similarity.
3) Neural Networks (Use the given Python codes to produce this solution)
(hint: try to use learning rate, α = 0.1, momentum rate, ŋ = 0.9 with epochs ≥ 3,000 iteration and
error term ≤ 0.01)
import math
import random
import sys
ALPHA = 0.1
MU = 0.9
N=4
M=4
NUM_CASES = 5
TEST_CASES = 3
class Frenz2:
def __init__(self, inputArray, x1, x2, target1, target2, alpha, mu, n, m, numCases, numTests):
self.mInputArray = inputArray
self.mX1 = x1
self.mX2 = x2
self.mTarget1 = target1
self.mTarget2 = target2
self.mAlpha = alpha
self.mMu = mu
self.mN = n
self.mM = m
self.mNumCases = numCases
self.mNumTests = numTests
self.hin = []
self.hout = []
self.oin = 0.0
self.oout = 0.0
self.inputNeuron = []
return
def initialize_arrays(self):
for i in range(self.mN):
self.hweight.append([0.0] * self.mM)
self.hweight2.append([0.0] * self.mM)
for j in range(self.mM):
self.hweight[i][j] = random.random() - 0.5 # hidden layer connections.
self.hweight2[i][j] = self.hweight[i][j] # copies for training.
for j in range(self.mM):
self.hbias.append(random.random() - 0.5) # hidden layer biases.
self.hbias2.append(self.hbias[j]) # copies for training.
self.oweight.append(random.random() - 0.5) # output layer connections.
self.oweight2.append(self.oweight[j]) # copies for training.
return
return floatOutput
total = 0.0
for j in range(m):
total = 0
for i in range(n):
total += (self.inputNeuron[i] * self.hweight[i][j])
for j in range(m):
self.hout[j] = self.sigmoid(self.hin[j])
return
for j in range(m):
total += (self.hout[j] * self.oweight[j])
for j in range(m):
hdelta = (d * self.oweight[j]) * self.sigmoid_derivative(self.hin[j])
for i in range(n):
dhweight[i][j] = (self.mAlpha * hdelta * self.inputNeuron[i]) + (self.mMu * (self.hweight[i][j] -
self.hweight2[i][j]))
self.hweight2[i][j] = self.hweight[i][j]
self.hweight[i][j] += dhweight[i][j]
return
for j in range(m):
doweight[j] = (self.mAlpha * odelta * self.hout[j]) + (self.mMu * (self.oweight[j] -
self.oweight2[j]))
self.oweight2[j] = self.oweight[j]
self.oweight[j] += doweight[j]
self.update_hidden(self.mN, m, odelta)
return
def train_network(self):
trainError = 0.0
j=0
trainingCycles = 0
trainingComplete = False
self.hidden_input(self.mN, self.mM)
self.output_input(self.mM)
self.oout = self.sigmoid(self.oin)
self.backpropagate(i, self.mM)
if j > 999:
if math.fmod(j, 1000) == 0:
sys.stdout.write(str(j) + " " + str(i) + " Expected: " + str(self.mTarget1[i]) + " Actual: " +
str(self.oout) + "\n")
j += 1
def examine_status(self):
self.inputNeuron[0] = self.mInputArray[0] # Gender.
self.inputNeuron[1] = self.mInputArray[1] # Entry Qualification.
self.inputNeuron[2] = self.mInputArray[2] # CGPA.
self.inputNeuron[3] = self.mInputArray[3] # English level.
self.hidden_input(self.mN, self.mM)
self.output_input(self.mM)
self.oout = self.sigmoid(self.oin)
if self.oout < 0:
sys.stdout.write("\nThe graduate student will working\n\n")
else:
sys.stdout.write("\nThe graduate student will unemployed\n\n")
return
def validate_net(self):
correct = 0
sys.stdout.write("Validating network training...\n")
for i in range(self.mNumTests):
for k in range(self.mN):
self.inputNeuron[k] = math.floor(self.mX2[i][k])
self.hidden_input(self.mN, self.mM)
self.output_input(self.mM)
self.oout = self.sigmoid(self.oin)
if self.mTarget2[i] == self.round(self.oout):
correct += 1
if correct >= 2:
sys.stdout.write(str(correct) + " out of " + str(self.mNumTests) + " Match. Validation
Successful.\n")
else:
sys.stdout.write(str(correct) + " out of " + str(self.mNumTests) + " Match. Validation
Unsuccessful.\n")
return
if __name__ == '__main__':
f2 = Frenz2(INPUTS, X1, X2, TARGET_VALUE1, TARGET_VALUE2, ALPHA, MU, N, M,
NUM_CASES, TEST_CASES)
f2.initialize_arrays()
f2.train_network()
f2.examine_status()
f2.validate_net()
Output:
1000 0 Expected: -1 Actual: -0.9954680265524264
1000 1 Expected: 0 Actual: 0.036856967502504334
1000 2 Expected: 1 Actual: 0.9823421617889561
1000 3 Expected: 0 Actual: 0.004714383403897848
1000 4 Expected: -1 Actual: -0.988105926056622
Training Error: 0.01925860063943935
Policy:
All grading of deliverables will be based on standards indicated for each deliverable. Deliverables may
not
be turned in late and no cheating! For the purposes of this class, cheating will include: plagiarism (using
the writings of another without proper citation), copying of another (either current or past student's
work), working with another on individually assigned work , or in any other way presenting as one's own
work that which is not entirely one's own work. The occurrence of plagiarism will result in removal from
the course with a failing grade.