How can I plot outliers in their correct position with respect to the original data?
12 ビュー (過去 30 日間)
古いコメントを表示
This plotting does not show the outliers in correct order. I want to plot the original data, and then mark the outliers in their correct order. The resulting graph is this. I want the red points in line with other data points. Any suggestions?
Temp = data(:,2); % Separating the feature vector
Temp_z_score = (Temp - mean(Temp)) / std(Temp); % Calculation of the z-score (z-score = the number of standard deviations a point is below or over the mean)
threshold = abs(Temp_z_score)>1.8; % Setting the outliers threshold
figure
plot(Temp(~threshold),'bo','DisplayName','Temperature')
hold on
plot(Temp(threshold),'r*','DisplayName','Outlier')
hold off
grid on
0 件のコメント
採用された回答
dpb
2022 年 10 月 15 日
You're just plotting the selected array elements against their ordinal number; you need a corollary x value against which to plot them...one could assume that would be the first column in the data array...
z_score=zscore(data(:,2));
isOut=abs(z_score)>1.8;
figure
plot(data(~isOut,1),data(~isOut,2),'bo','DisplayName','Temperature')
hold on
plot(data(isOut,1),data(isOut,2),'r*','DisplayName','Outlier')
hold off
grid on
If the actual x values aren't the first column after all, then use
plot(find(~isOut),data(~isOut,2),'bo','DisplayName','Temperature')
hold on
plot(find(isOut),data(isOut,2),'r*','DisplayName','Outlier')
instead to return the locations in the original vector
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!