Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SERP Analysis - Abnormal Impressions by Query
from sklearn.ensemble import IsolationForest
def print_anomalies(query,column):
df_anom = df[(df['query'] == query) & (df['device'] == 'desktop')]
xx = np.linspace(df_anom[column].min(), df_anom[column].max(), len(df)).reshape(-1,1)
isolation_forest = IsolationForest(n_estimators=100), 1))
anomaly_score = isolation_forest.decision_function(xx)
# 1 = inlier, 0 = outlier
outlier = isolation_forest.predict(xx)
df_outliers = df_anom[list(map(lambda v: True if v < 0 else False,isolation_forest.predict(x.reshape(-1, 1))))]
df_outliers = df_outliers[ >= - datetime.timedelta(days=14)]
for q in top_queries_by_clicks:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.