From 3c9cd991fb163890655a6a6738183f2e4929176f Mon Sep 17 00:00:00 2001 From: pbp85j3ha <3378631420@qq.com> Date: Tue, 18 Jun 2024 11:40:47 +0800 Subject: [PATCH] ADD file via upload --- day_02_code.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 day_02_code.py diff --git a/day_02_code.py b/day_02_code.py new file mode 100644 index 0000000..317bcd8 --- /dev/null +++ b/day_02_code.py @@ -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}') +