6 Task RBF
6 Task RBF
Assuming a set of documents that need to be classified, use the Radial basis function Classifier
model to perform this task. Calculate the classification rate, accuracy, precision, and recall for
your data set.
Methodology
Radial basis function network (or RBFN for short) is an artificial neural network that uses radial
basis functions as activation functions. The output of the network is a linear combination of
radial basis functions of the inputs and neuron parameters.
Requirements:
Code
impor
t
numpy
as np
import time
import re
import sys
import math
import matplotlib.pyplot as plt
np.set_printoptions(threshold=sys.maxsize, suppress=True)
np.random.seed(1)
dataSize = 10000
data = sampleData[:dataSize]
for i in range(15):
centeriodSums = np.zeros(shape=centeriods.shape)
centeriodSumsCounter = np.zeros(shape=K)
class Network:
def __init__(self):
self.XSize = 0
self.HSize = 300
self.OSize = 10
self.X = []
self.C = []
self.Y = []
self.W = []
# self.B = np.random.uniform(-1, 1, (self.OSize))
self.trainErrors = []
self.testErrors = []
def predict(self):
"""Predicts using the Network by the set parameters (weight and
centers) and displays the accuracy
"""
self.testErrors = np.zeros(shape=self.XSize) # Preallocatingnumpy array
print("Prediciting...")
totalAvg = count = correctCount = 0.0
# Take each data sample from the inputData
for count, x in enumerate(self.X):
HLayer = rbf(x, self.C)
output = np.dot(HLayer, self.W) # + self.B
o = np.argmax(output)
y = np.argmax(self.Y[count])
if o == y:
correctCount += 1