Outlier Detection of a matrix depending on spatio coordinates
古いコメントを表示
Hi, I have thousands of matrices, each of (130x160) with values (range of -25 up to +25) consisting of outliers.The values of the matrix depending on spatial data x(1:130) and Y(1:160). Outliers are often within the range and sometimes not only single values, clustering across 2 or 3 values across the raws and/or columns (X or Y) of the matrix.
I already tried "filloutliers" and deleteoutliers (https://de.mathworks.com/matlabcentral/fileexchange/3961-deleteoutliers)
with rather average level of satisfaction.
Can anyone recommend an appropriate method to detect the outliers? What kind of ML algorithms could I try?
Thanks,
Chris
14 件のコメント
Dyuman Joshi
2023 年 8 月 15 日
CSCh
2023 年 8 月 15 日
Dyuman Joshi
2023 年 8 月 15 日
Yes, the methods for finding outliers are the same for both.
And none of those worked for you?
Could you attach a sample of your data?
Constantino Carlos Reyes-Aldasoro
2023 年 8 月 16 日
Have you tried the traditional mean +- 3 * standard deviation criterion to determine what is an outlier?
CSCh
2023 年 8 月 17 日
CSCh
2023 年 8 月 17 日
Alan
2023 年 8 月 23 日
Hi CSCh,
I understand that you want to detect outliers within each matrix rather than considering each matrix as datapoints.
In that case, you can try to fit a surface to each matrix and evaluate the z-score of the matrix (considering the fitted surface as the mean). You could exclude the points whose absolute z-score crosses a certain threshold. Here is an example in 1-D: https://in.mathworks.com/help/curvefit/removing-outliers.html?s_tid=srchtitle_support_results_2_outliers#RemoveOutliersExample-2
Here is how you can fit a surface using the fit function instead of fitting a curve as shown in the above example:
x = 1:130;
y = 1:160;
[X Y] = meshgrid(x, y);
% Generating a matrix for this example
Z = 25 * sin(2 * pi / 130 / 160 * (X.^2 + Y.^2));
% Fitting surface
xdata = reshape(X, 1, [])';
ydata = reshape(Y, 1, [])';
zdata = reshape(Z, 1, [])';
fitted_surface = fit([xdata ydata], zdata, "poly23");
% Visualize fitted surface against the matrix
plot(fitted_surface, [xdata ydata], zdata)
legend(["Fitted Surface"]);
% Continue to calculate z-score and exclude outliers
In case you are considering each matrix as a datapoint, consider combining the matrices and find the outliers along the z-axis. The following functions could be utilized:
- isoutlier() - https://in.mathworks.com/help/matlab/ref/isoutlier.html
- rmoutliers() - https://in.mathworks.com/help/matlab/ref/rmoutliers.html
- filoutliers() - https://in.mathworks.com/help/matlab/ref/filloutliers.html
Some parameters to experiment with could be:
- dim : Dimension along which the outliers should be detected.
- movemethod : To detect outliers using a moving window.
- percentiles : To identify the extreme percentile of data.
As for machine learning methods, you could check out this resource: https://in.mathworks.com/help/stats/unsupervised-anomaly-detection.html. It contains various supervised methods for multivariate data.
CSCh
2023 年 8 月 24 日
Alan
2023 年 8 月 25 日
Could you try running the exact code? It is supposed to give the following output:

If you are providing your own input data to the code, ensure that you are maintaining the right format.
CSCh
2023 年 8 月 25 日
移動済み: Bruno Luong
2023 年 8 月 25 日
Bruno Luong
2023 年 8 月 25 日
fit belongs to curve fitting toolbox do you have access to it?
CSCh
2023 年 8 月 25 日
Bruno Luong
2023 年 8 月 25 日
Because you have another fit somewhere else I guess.
Alan
2023 年 9 月 4 日
I had intended to post my answer in the "Answers" section instead of the "Coments" section. Therefore I shall repost it in the "Answers" section. I hope that the OP and others looking for a solution to a similar problem will find the resources to be helpful.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Exploration and Visualization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
