| import pandas as pd | |
| from sklearn.ensemble import IsolationForest | |
| def clean_data(file): | |
| df = pd.read_csv(file) | |
| # Konversi tanggal | |
| df['tanggal'] = pd.to_datetime(df['tanggal']) | |
| # Deteksi anomaly | |
| clf = IsolationForest(contamination=0.05) | |
| df['anomaly'] = clf.fit_predict(df[['demand', 'supply']]) | |
| return df[df['anomaly'] == 1].drop('anomaly', axis=1) |