from metric_learn import NCA
from sklearn.datasets import make_classification
from sklearn.neighbors import KNeighborsClassifier
nca = NCA()
X, y = make_classification()
nca.fit(X, y)
print(nca.transform(X).shape)
knn = KNeighborsClassifier(metric=nca.get_metric())
knn.fit(X, y)
print(knn.predict(X[0 : 2, :]))
#http://contrib.scikit-learn.org/metric-learn/generated/metric_learn.NCA.html#metric_learn.NCA
转载自原文链接, 如需删除请联系管理员。
原文链接:度量学习(NCA),转载请注明来源!