Exemplo n.º 1
0
def getErrorRate(logP, yActual):
    predictedRes = getPredictions(logP)
    yActual = yActual.flatten().astype(int)
    return np.mean(predictedRes != yActual)


def getPredictions(logP):
    predictedClass = np.argmax(logP, axis=1)
    return predictedClass


# %%

# Load data from spamData.mat
xtrain, ytrain, xtest, ytest = du.loadData('spamData.mat')
xtrain = du.binarization(xtrain)
xtest = du.binarization(xtest)

# Create an array of alpha values, from 0 to 100 with step size 0.5
alphaStart = 0
alphaEnd = 100
alphaStepSize = 0.5
alphaArr = np.arange(alphaStart, alphaEnd + alphaStepSize, alphaStepSize)

trainErr = np.zeros(len(alphaArr))
testErr = np.zeros(len(alphaArr))

# %%

for j in range(len(alphaArr)):
    alpha = alphaArr[j]