zscore 이용한 이상치 탐색(1)에서 구한 outlier들을 이용하여 plot위에 나타내 준다.
방법은 간단하게 아래와 같다.
import plotly.express as px
## outliers 는 이전의 글 zscore 이용한 이상치 탐색(1)에서 가져오면 된다.
threshold = 1 #or 2 or 3
outliers = np.abs(zscore(iris_df['sepal length (cm)'])) > threshold
fig = px.scatter(iris_df, y = 'sepal length (cm)', color = outliers
fig.show()
여기서 threshold 값을 2 혹은 3값을 움직이면 outlier로 처리된 빨간색의 양이 줄어드는 것을 볼 수 있다.
threshold = 1 # or 2 or 3
outliers = outliers
fig2 = px.histogram(iris_df['sepal length (cm)'], color = outliers, nbins = 30)
# nbins 값이 높아질 수록 나타나는 바의 양이 많아진다.
fig2.update_traces(marker_line_color = 'black', marker_line_width = 1)
# 바에 검은색 테두리 입히는 방법. 개인적으로 이게 좀더 깔끔해보여서 항상 histogram 그릴때마다 추가한다.
fig2.show()