【案例】给定10组肿瘤相关数据的特征值[3.3935, 2.3312], [3.1101, 1.7815], [1.3438, 3.3684], [3.5823, 4.6792], [2.2804, 2.8670], [7.4234, 4.6965], [5.7451, 3.5340], [9.1722, 2.5111], [7.7928, 3.4241], [7.9398, 0.7916],还有其对应的目标值[0, 0, 0, 0, 0, 1, 1, 1, 1, 1](0代表良性肿瘤,1代表恶性肿瘤)。先给出一个待测样本[8.0936, 3.3657],试使用kNN算法推断其目标值。
一. 导入数据集:
1. 导入需要的相关模块:
import numpy as np
import matplotlib.pyplot as plt
2. 导入数据集:
row_data_X = [[3.3935, 2.3312],
[3.1101, 1.7815],
[1.3438, 3.3684],
[3.5823, 4.6792],
[2.2804, 2.8670],
[7.4234, 4.6965],
[5.7451, 3.5340],
[9.1722, 2.5111],
[7.7928, 3.4241],
[7.9398, 0.7916]]
# 0:良性肿瘤,1:恶性肿瘤
row_data_y = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]