parent
3c09f8cf69
commit
3c9cd991fb
@ -0,0 +1,32 @@
|
|||||||
|
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}')
|
||||||
|
|
Loading…
Reference in new issue