How to remove Outliers

101 visualizaciones (últimos 30 días)
Huy Cao
Huy Cao el 29 de Nov. de 2021
Comentada: Steven Lord el 21 de Mzo. de 2022
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

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 29 de Nov. de 2021
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 comentarios
Mathieu NOE
Mathieu NOE el 30 de Nov. de 2021
attached the smoothn function (FYI)
Mathieu NOE
Mathieu NOE el 1 de Dic. de 2021
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');

Iniciar sesión para comentar.

Más respuestas (2)

John D'Errico
John D'Errico el 29 de Nov. de 2021
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 comentario
Steven Lord
Steven Lord el 21 de Mzo. de 2022
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

Iniciar sesión para comentar.


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

Categorías

Más información sobre Descriptive Statistics en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by