How to remove Outliers

67 次查看(过去 30 天)
Huy Cao
Huy Cao 2021-11-29
Hi everyone. Does anyone know how to detect and remove the outliers? I've tried man ways but I can't. I have to remove the data by Excel but I think that's not enough. Thank youuuu

采纳的回答

Mathieu NOE
Mathieu NOE 2021-11-29
hello
here is a quick result after a few manipulations
code
clc
clearvars
T = readtable('AskingData.xlsx');
P = T.Power;
Ws = T.WingSpeed;
% remove duplicates
[Ws_unique,IA,IC] = unique(Ws);
P_unique = P(IA);
% remove negative Power
ind = find(P_unique<0);
P_unique(ind) = [];
Ws_unique(ind) = [];
% remove outliers
[P_unique2,TF] = rmoutliers(P_unique,'movmedian',100);
Ws_unique2 = Ws_unique(~TF);
% let's add some smoothing
P_unique2S = smoothdata(P_unique2,'sgolay',151);
plot(Ws_unique,P_unique,'b*',Ws_unique2,P_unique2,'r--',Ws_unique2,P_unique2S,'g');
legend('unique','unique and outliers removed','smoothed');
  9 个评论
Mathieu NOE
Mathieu NOE 2021-11-30
attached the smoothn function (FYI)
Mathieu NOE
Mathieu NOE 2021-12-1
it's me again !
I tried another smoothing function (irlssmooth) found on the file exchange :
this one is also very good with outliers
see the benefit vs built in smoothdata from TMW
code :
clc
clearvars
T = readtable('AskingData.xlsx');
P = T.Power;
Ws = T.WingSpeed;
% remove duplicates
[Ws_unique,IA,IC] = unique(Ws);
P_unique = P(IA);
% remove negative Power
ind = find(P_unique<0);
P_unique(ind) = [];
Ws_unique(ind) = [];
% smooth the data
P_uniqueS = smoothdata(P_unique,'movmedian',80);
P_uniqueS2 = irlssmooth(P_unique,80); % good !! % see FEX : https://fr.mathworks.com/matlabcentral/fileexchange/49788-robust-least-squares-smoother?s_tid=srchtitle_irlssmooth_1
plot(Ws_unique,P_unique,'b*',Ws_unique,P_uniqueS,'r',Ws_unique,P_uniqueS2,'g');
legend('unique','smoothdata','irlssmooth');

请先登录,再进行评论。

更多回答(2 个)

John D'Errico
John D'Errico 2021-11-29
The obvious answer is to look at the tools provided in MATLAB. Thus RMOUTLIERS, ISOUTLIER, etc. They are provided in the stats toolbox.
Or if you want to do the work yourself, use tools to do local filtering of some sort. For example, a local polynomial model that drops out the point at the center, but predicts a value there. In a time series context, this can reduce to a simple call to CONV with the correct kernel. (Not difficult to compute that kernel either.) Now compare the predicted value to the point left out. Those with large residuals are potential outliers.
You can also use tools for robust regression modeling, then identifying any points with large residuals as a possible outlier.
The data you show appears to have multiple problems though. There appears to be at least one region with a large dropout, an obvious outlier cluster, possibly caused by some sort of equiptment issues. Outlier detection schemes tend to be best at detecting single point outliers. Groups of outliers are far more difficult to detect, because these points all look like the data around them.
You might also look into clustering methods.
And that means you probably need to make an effort to clean up your data manually. Look for problems in the data that are obvious. If possible, then look back at the source of your data to see if there was some reason for the problem.
  1 个评论
Steven Lord
Steven Lord 2022-3-21
FYI rmoutliers and isoutlier are part of MATLAB not Statistics and Machine Learning Toolbox.
which rmoutliers
/MATLAB/toolbox/matlab/datafun/rmoutliers.m
which isoutlier
/MATLAB/toolbox/matlab/datafun/isoutlier.m

请先登录,再进行评论。


Sean Harvey
Sean Harvey 2022-3-21
编辑:Sean Harvey 2022-3-21
Did you find a way to remove only the outliers (i.e., points away from the S-shaped curve)?

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by