我想从下面的图表中删除这9个橙色的异常点,为此我需要计算每个橙色点的准确度分数,并选择9个最低的。我怎么能做到呢?我知道可以计算整个预测精度的函数,但有什么方法可以对每个点进行精确计算吗?在
我试过这样做,但是从这里得到的x和y值与图上的异常值不匹配。(我使用的是sklearn线性回归)score_array = []
for i in range(len(x_train)):
#reshaping to fit the predict() function
x = np.array(x_train[i]).reshape(1, -1)
pred = clf.predict(x)
# calculating square difference of y_expected and y_predicted
score = y_train[i]**2 - pred**2
score_array.append(score) # array containing score for each dot
# larger the difference between squares, higher chance of being an outlier
# sorting array in descending order
score_array = sorted(score_array, key = float, reverse = True)
# first 9 members will have largest difference of squares
# outlier_score array contains score of 9 dots we want to remove
outlier_score = score_array[0:9]
outlier