import numpy as np from sklearn.neighbors import KNeighborsRegressor # 回归 import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] x = np.array(x).reshape(-1,1) y = [9, 12, 1, 6, 7] plt.scatter(x, y) plt.show() model = KNeighborsRegressor(n_neighbors=3) model.fit(x,y) print(model.predict([[1.5]])) print(model.predict([[3.52]]))
有监督学习之KNN回归问题
最新推荐文章于 2024-07-11 21:12:02 发布