第1关使用sklearn中的kNN算法进行分类

from sklearn.neighbors import KNeighborsClassifierdef classification(train_feature, train_label, test_feature):'''使用KNeighborsClassifier对test_feature进行分类:param train_feature: 训练集数据:param train_label: 训练集标签:param test_feature: 测试集数据:return: 测试集预测结果'''#********* Begin *********#clf = KNeighborsClassifier()clf.fit(train_feature, train_label)return clf.predict(test_feature)#********* End *********#

第2关使用sklearn中的kNN算法进行回归

from sklearn.neighbors import KNeighborsRegressordef regression(train_feature, train_label, test_feature):'''使用KNeighborsRegressor对test_feature进行分类:param train_feature: 训练集数据:param train_label: 训练集标签:param test_feature: 测试集数据:return: 测试集预测结果'''#********* Begin *********#clf=KNeighborsRegressor() clf.fit(train_feature, train_label) return clf.predict(test_feature)#********* End *********#