Exemplo n.º 1
0
# Vindt de optimale K met behulp van de validatieset en beantwoordt de vraag met deze K.
from kNN import findK, scale, genDataSet, genLabels, findLabel, findminmax, scale2
import time

#generate dataset and validationset
data = genDataSet("dataset1.csv")

scalers = findminmax(data)
weights = [1, 1, 2, 4, 2, 1, 3]

scaleddata = scale2(data, scalers, weights)
scaledvaliddata = scale2(genDataSet("validation1.csv"), scalers, weights)
scaledtestdata = scale2(genDataSet("days.csv"), scalers, weights)

#generate labels for aformentioned sets
labels = genLabels("dataset1.csv", 2000)
validlabels = genLabels("validation1.csv", 2001)

# #find optimal K value and corresponding accuracy
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print(current_time)
accuracy, optimalK = findK(scaleddata, scaledvaliddata, labels, validlabels)
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print(current_time)

# # generate and print labels for testdata
print(findLabel(scaleddata, scaledtestdata, labels, optimalK))
print("Used K: ", optimalK)
print("Accuracy validationset: ", accuracy)
Exemplo n.º 2
0
# Beantwoordt de vraag met gegeven K
from kNN import findK, scale, genDataSet, genLabels, findLabel

#generate dataset
scaleddata = scale(genDataSet("dataset1.csv"))
#generate validationset
scaledtestdata = scale(genDataSet("days.csv"))

#generate list of labels for dataset
labels = genLabels("dataset1.csv", 2000)

#generate and print labels for testdata
print(findLabel(scaleddata, scaledtestdata, labels, 61))