當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。