当前位置: 首页>>代码示例>>Python>>正文


Python KNN.eval方法代码示例

本文整理汇总了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


开发者ID:Wummer,项目名称:ML1,代码行数:30,代码来源:main.py

示例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 







开发者ID:MariaBarrett,项目名称:Datamining,代码行数:25,代码来源:main.py


注:本文中的KNN.eval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。