from sklearn.mixture import GaussianMixture Initialize the GMM model (we assume there…
- User
from sklearn.mixture import GaussianMixture
Initialize the GMM model (we assume there could be 2 clusters, but this can vary)
gmm = GaussianMixture(n_components=2, covariance_type='full', random_state=42)
Fit the model to the salary data
gmm.fit(salary_data[['salary']])
Get the probability density (likelihood) of each point belonging to the mixture components
salary_data['gmm_score'] = gmm.score_samples(salary_data[['salary']])
Define an outlier threshold - very low likelihood values will be considered anomalies
threshold = salary_data['gmm_score'].quantile(0.05) # Example threshold at 5% quantile
Mark outliers based on the threshold
outliers_gmm = salary_data[salary_data['gmm_score'] < threshold]
Show detected outliers
outliers_gmm
- Assistant