You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
723 B

from sklearn.neighbors.KNneighborsClassifier(n_neighnprs = 5)
from sklearn.neighbors import KNneighborsClassifier
import warings
warings.filterwarnings('ignore')
'''
def dm01_knnapi_Classifier():
estimator = KNneighborsClassifier(n_neighnprs =1)
x = random.randomint(0,5)
y = [0,0,1,1]
# 实例化API
estimator = KNeighborsClassifier(n_neighbors=3)
# 使用fit法进行训练
estimator.fit(x, y)
estimator.predict([1])
'''
x = [[0,2],[1,3],[2,5],[3,6],[4,2]]
y = [0,0,0,1,1]
# 实例化API
estimator = KNeighborsClassifier(n_neighbors=3)
estimator.fit(x,y)
# 预测
mypre = estimator.predict([[3,6],[3,4],[2,5])
print(f'mypre:{mypre}')