teceai

Untitled

May 11th, 2021
702
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. from sklearn.ensemble import IsolationForest
  3.  
  4. df = pd.read_csv('/datasets/sales.csv')
  5. data = df[['Sales', 'Profit']]
  6.  
  7. sales = df['Sales'].values.reshape(-1, 1)
  8. profit = df['Profit'].values.reshape(-1, 1)
  9.  
  10. isolation_forest = IsolationForest(n_estimators=100)
  11. isolation_forest.fit(data)
  12. #estimator = isolation_forest.predict(data)
  13. estimator = isolation_forest.fit_predict(data)
  14.  
  15. outliers = []
  16. outliers.append(estimator == -1)
  17.  
  18. print("Количество аномалий: ", len(outliers))
RAW Paste Data