diff --git a/uq_ml_models_FS/fs_UQ_ABC.py b/uq_ml_models_FS/fs_UQ_ABC.py index 23e5f8d..c91f0e2 100644 --- a/uq_ml_models_FS/fs_UQ_ABC.py +++ b/uq_ml_models_FS/fs_UQ_ABC.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [AdaBoostClassifier(**rs)] diff --git a/uq_ml_models_FS/fs_UQ_BC.py b/uq_ml_models_FS/fs_UQ_BC.py index 776db9f..c6273cd 100644 --- a/uq_ml_models_FS/fs_UQ_BC.py +++ b/uq_ml_models_FS/fs_UQ_BC.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [BaggingClassifier(**rs diff --git a/uq_ml_models_FS/fs_UQ_BNB.py b/uq_ml_models_FS/fs_UQ_BNB.py index 9092c2d..8193431 100644 --- a/uq_ml_models_FS/fs_UQ_BNB.py +++ b/uq_ml_models_FS/fs_UQ_BNB.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [BernoulliNB()] diff --git a/uq_ml_models_FS/fs_UQ_DT.py b/uq_ml_models_FS/fs_UQ_DT.py index bed047b..b62043a 100644 --- a/uq_ml_models_FS/fs_UQ_DT.py +++ b/uq_ml_models_FS/fs_UQ_DT.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [DecisionTreeClassifier(**rs)] diff --git a/uq_ml_models_FS/fs_UQ_GBC.py b/uq_ml_models_FS/fs_UQ_GBC.py index d692ce1..eca536a 100644 --- a/uq_ml_models_FS/fs_UQ_GBC.py +++ b/uq_ml_models_FS/fs_UQ_GBC.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [GradientBoostingClassifier(**rs)] diff --git a/uq_ml_models_FS/fs_UQ_GNB.py b/uq_ml_models_FS/fs_UQ_GNB.py index 3dab3c0..cfcca4b 100644 --- a/uq_ml_models_FS/fs_UQ_GNB.py +++ b/uq_ml_models_FS/fs_UQ_GNB.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [GaussianNB()] diff --git a/uq_ml_models_FS/fs_UQ_GPC.py b/uq_ml_models_FS/fs_UQ_GPC.py index 2fc5a88..dd425d0 100644 --- a/uq_ml_models_FS/fs_UQ_GPC.py +++ b/uq_ml_models_FS/fs_UQ_GPC.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [GaussianProcessClassifier(**rs)] diff --git a/uq_ml_models_FS/fs_UQ_KNN.py b/uq_ml_models_FS/fs_UQ_KNN.py index 88b8fa0..1145dcf 100644 --- a/uq_ml_models_FS/fs_UQ_KNN.py +++ b/uq_ml_models_FS/fs_UQ_KNN.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [KNeighborsClassifier(**njobs)] diff --git a/uq_ml_models_FS/fs_UQ_LR.py b/uq_ml_models_FS/fs_UQ_LR.py index 879a926..8691d4b 100644 --- a/uq_ml_models_FS/fs_UQ_LR.py +++ b/uq_ml_models_FS/fs_UQ_LR.py @@ -12,75 +12,6 @@ Created on Tue Mar 15 11:09:50 2022 @author: tanu """ -#%% Import libs -import numpy as np -import pandas as pd -from sklearn.model_selection import GridSearchCV -from sklearn import datasets -from sklearn.ensemble import ExtraTreesClassifier -from sklearn.ensemble import RandomForestClassifier -from sklearn.ensemble import AdaBoostClassifier -from sklearn.ensemble import GradientBoostingClassifier -from sklearn.svm import SVC - -from sklearn.base import BaseEstimator -from sklearn.naive_bayes import MultinomialNB -from sklearn.linear_model import SGDClassifier -from sklearn.pipeline import Pipeline -from sklearn.model_selection import GridSearchCV -from sklearn.linear_model import LogisticRegression -from sklearn.preprocessing import StandardScaler, MinMaxScaler, OneHotEncoder -from xgboost import XGBClassifier -rs = {'random_state': 42} -njobs = {'n_jobs': 10} -#%% Get train-test split and scoring functions -# X_train, X_test, y_train, y_test = train_test_split(num_df_wtgt[numerical_FN] -# , num_df_wtgt['mutation_class'] -# , test_size = 0.33 -# , random_state = 2 -# , shuffle = True -# , stratify = num_df_wtgt['mutation_class']) - -y.to_frame().value_counts().plot(kind = 'bar') -blind_test_df['dst_mode'].to_frame().value_counts().plot(kind = 'bar') - -scoring_fn = ({'accuracy' : make_scorer(accuracy_score) - , 'fscore' : make_scorer(f1_score) - , 'mcc' : make_scorer(matthews_corrcoef) - , 'precision' : make_scorer(precision_score) - , 'recall' : make_scorer(recall_score) - , 'roc_auc' : make_scorer(roc_auc_score) - , 'jaccard' : make_scorer(jaccard_score) - }) - -mcc_score_fn = {'mcc': make_scorer(matthews_corrcoef)} -jacc_score_fn = {'jcc': make_scorer(jaccard_score)} - -#%% Logistic Regression + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [LogisticRegression(**rs)], diff --git a/uq_ml_models_FS/fs_UQ_MLP.py b/uq_ml_models_FS/fs_UQ_MLP.py index 8c84e04..9695f35 100644 --- a/uq_ml_models_FS/fs_UQ_MLP.py +++ b/uq_ml_models_FS/fs_UQ_MLP.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [MLPClassifier(**rs diff --git a/uq_ml_models_FS/fs_UQ_QDA.py b/uq_ml_models_FS/fs_UQ_QDA.py index 5024c3c..c34b862 100644 --- a/uq_ml_models_FS/fs_UQ_QDA.py +++ b/uq_ml_models_FS/fs_UQ_QDA.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [QuadraticDiscriminantAnalysis()] diff --git a/uq_ml_models_FS/fs_UQ_RC.py b/uq_ml_models_FS/fs_UQ_RC.py index 2ea710f..f2a21de 100644 --- a/uq_ml_models_FS/fs_UQ_RC.py +++ b/uq_ml_models_FS/fs_UQ_RC.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ {'clf__estimator' : [RidgeClassifier(**rs)] , 'clf__estimator__alpha': [0.1, 0.2, 0.5, 0.8, 1.0] diff --git a/uq_ml_models_FS/fs_UQ_RF.py b/uq_ml_models_FS/fs_UQ_RF.py index 7758f9a..f87b87d 100644 --- a/uq_ml_models_FS/fs_UQ_RF.py +++ b/uq_ml_models_FS/fs_UQ_RF.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [RandomForestClassifier(**rs diff --git a/uq_ml_models_FS/fs_UQ_SVC.py b/uq_ml_models_FS/fs_UQ_SVC.py index c430649..336746d 100644 --- a/uq_ml_models_FS/fs_UQ_SVC.py +++ b/uq_ml_models_FS/fs_UQ_SVC.py @@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022 @author: tanu """ -#%% RandomForest + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [SVC(**rs)] diff --git a/uq_ml_models_FS/fs_UQ_XGB.py b/uq_ml_models_FS/fs_UQ_XGB.py index 65a5e8f..576613d 100644 --- a/uq_ml_models_FS/fs_UQ_XGB.py +++ b/uq_ml_models_FS/fs_UQ_XGB.py @@ -16,31 +16,6 @@ Created on Wed May 18 06:03:24 2022 # reg_lambda=1, scale_pos_weight=1, seed=None, silent=None, # subsample=1, verbosity=1) -#%% XGBoost + hyperparam: BaseEstimator: ClfSwitcher() -class ClfSwitcher(BaseEstimator): - def __init__( - self, - estimator = SGDClassifier(), - ): - """ - A Custom BaseEstimator that can switch between classifiers. - :param estimator: sklearn object - The classifier - """ - self.estimator = estimator - - def fit(self, X, y=None, **kwargs): - self.estimator.fit(X, y) - return self - - def predict(self, X, y=None): - return self.estimator.predict(X) - - def predict_proba(self, X): - return self.estimator.predict_proba(X) - - def score(self, X, y): - return self.estimator.score(X, y) - parameters = [ { 'clf__estimator': [XGBClassifier(**rs , **njobs, verbose = 3)]