Giter VIP home page Giter VIP logo

isolationforest's People

Contributors

elena-sharova avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

isolationforest's Issues

TypeError: cannot convert the series to <class 'int'> when trying GridSearchCV

I have a problem regarding section 4 of notebook (4. Setting Parameters of Isolation Forest - n_estimators) I want to print the optimized number of trees which is n_estimators as follows:

#import libraries
from sklearn import datasets
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.metrics import recall_score, silhouette_score, roc_curve, roc_auc_score, f1_score, precision_recall_curve, auc
from sklearn.model_selection import GridSearchCV

# The part of notebook related to section 4 (4. Setting Parameters of Isolation Forest - n_estimators)
scoring = {'AUC': 'roc_auc', 'Recall': make_scorer(recall_score, pos_label=-1)}

gs = GridSearchCV(IsolationForest(max_samples=0.25, random_state=11, contamination = 0.15, n_jobs=-1),
                  param_grid={'n_estimators': range(20, 230, 30)},
                  scoring=scoring, refit='Recall', return_train_score=True, cv=3, verbose=1, n_jobs=-1)
gs.fit(X_train_sf, y_train_sf)
results = gs.cv_results_

#Frame the results via pandas
pd.DataFrame(results)

#print the best n_estimators based on recall metric
max_recall_n_estimators = int(pd.DataFrame(results)[["param_n_estimators", "mean_train_Recall"]].loc[pd.DataFrame(results)["mean_train_Recall"] == pd.DataFrame(results)["mean_train_Recall"].max()]["param_n_estimators"])
max_recall_n_estimators 

visually I need to access the marked part on plot which is the optimum value on train-set and test-set based on recall metric:
img

and I get the error which its Traceback is following:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-61-95626cf7130a> in <module>
----> 1 max_recall_n_estimators = int(pd.DataFrame(results)[["param_n_estimators", "mean_train_Recall"]].loc[pd.DataFrame(results)["mean_train_Recall"] == pd.DataFrame(results)["mean_train_Recall"].max()]["param_n_estimators"])
      2 max_recall_n_estimators = max_recall_n_estimators.astype(int)

/opt/anaconda3/envs/.../lib/python3.8/site-packages/pandas/core/series.py in wrapper(self)
    137         if len(self) == 1:
    138             return converter(self.iloc[0])
--> 139         raise TypeError(f"cannot convert the series to {converter}")
    140 
    141     wrapper.__name__ = f"__{converter.__name__}__"

TypeError: cannot convert the series to <class 'int'>

I already checked this answer1 & answer2 via .astype(int) but I couldn't figure it out how I can return/print max_recall_n_estimators from results of GridSearchCV elegantly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.