本文整理汇总了Python中KNN.eval方法的典型用法代码示例。如果您正苦于以下问题:Python KNN.eval方法的具体用法?Python KNN.eval怎么用?Python KNN.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KNN
的用法示例。
在下文中一共展示了KNN.eval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1:
# 需要导入模块: import KNN [as 别名]
# 或者: from KNN import eval [as 别名]
print "Scaled test set"
just_for_getting_mean_on_scaled_test_set = KNN.meanfree(transformed_test)
print "-" * 45
#Different K
K = [1,3,5]
Kcrossval = [1,3,5,7,9,11,13,15,17,21,25]
Kbest = [15]
Kbest2 = [1,21]
#Calling KNN
print "*" * 45
print "KNN"
print "*" * 45
for k in Kcrossval: #here you can switch between different lists of K: K, Kcrosscal, Kbest, Kbest2
losstrain, losstest = KNN.eval(zeromean_train, transformed_test,k) # switch between datasets: train_set, test_set, zeromean_train, transformed_test
print "-"*45
print "Number of neighbors: \t%d" %k
print "0-1 loss train:\t%1.4f" %losstrain
print "Accuracy train:\t%1.4f" %round(1.0-losstrain,4)
print "0-1-loss test:\t%1.4f" %losstest
print "Accuracy test:\t%1.4f" %round(1.0-losstest,4)
print "-"*45
# Calling crossval
#Example on how to call: KNN.crossval(dataset, number_of folds)
KNN.crossval(train_set, 5) #Switch between zeromean_train and train_set
示例2:
# 需要导入模块: import KNN [as 别名]
# 或者: from KNN import eval [as 别名]
temp = []
temp.append(standardized_prog_skills[i])
temp.append(binary_os[i][0]) #ugly hard-coded way of getting elements out of list
temp.append(binary_os[i][1])
temp.append(binary_os[i][2])
temp.append(snow_num[i])
num_features.append(temp)
num_features = np.array(num_features) #feature set [age, 3 binary values for operating sys, tiredness of snow]
#Calling k-means
Kmeans.kmeans(num_features)
#Calling KNN
#making a train and a test set. The label is the last value: tiredness of snow.
train = num_features[:50] #50 datapoints in train set
test = num_features[50:] # the remanining 17 datapoints in test set
k = 3
Error = KNN.eval(train, test, k)
print "*" *45
print "K-nearest neighbor"
print "*" * 45
print "k = ", k
print "Error on testset:", Error