This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import function, or patch it: | |
# Note: may need to install mlxtend | |
try: | |
from sklearn.inspection import permutation_importance | |
except ImportError: | |
print("Problem importing permutation_importance -- patching") | |
from mlxtend.evaluate import feature_importance_permutation | |
def permutation_importance(estimator, X, y, scoring='r2', n_repeats=5): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import GridSearchCV | |
from sklearn.metrics import make_scorer | |
# import Random Forest | |
param_grid = {'n_estimators': [50, 100, 200], | |
'max_depth':[None, 10, 15, 20], | |
'criterion': ['gini', 'entropy'], | |
'min_impurity_decrease': [0, 1e7, 1e5]} | |
scorer = make_scorer(accuracy_score) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import Random Forest | |
base_rf = RandomForestClassifier(n_estimators=100, max_depth=None) | |
base_rf.fit(train_X, train_y) | |
depths = [est.tree_.max_depth for est in base_rf.estimators_] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is a custom module | |
import assess_clf_models as acm | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.ensemble import GradientBoostingClassifier, RandomForestClassifier, BaggingClassifier | |
from catboost import CatBoostClassifier | |
from sklearn.compose import ColumnTransformer | |
from sklearn.preprocessing import StandardScaler, OneHotEncoder, FunctionTransformer |
NewerOlder