remove ClfSwitcher() from this lot

This commit is contained in:
Tanushree Tunstall 2022-05-22 23:36:24 +01:00
parent 18d9b77aee
commit 1a1154b4f4
15 changed files with 0 additions and 419 deletions

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [AdaBoostClassifier(**rs)] 'clf__estimator': [AdaBoostClassifier(**rs)]

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [BaggingClassifier(**rs 'clf__estimator': [BaggingClassifier(**rs

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [BernoulliNB()] 'clf__estimator': [BernoulliNB()]

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [DecisionTreeClassifier(**rs)] 'clf__estimator': [DecisionTreeClassifier(**rs)]

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [GradientBoostingClassifier(**rs)] 'clf__estimator': [GradientBoostingClassifier(**rs)]

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [GaussianNB()] 'clf__estimator': [GaussianNB()]

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [GaussianProcessClassifier(**rs)] 'clf__estimator': [GaussianProcessClassifier(**rs)]

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [KNeighborsClassifier(**njobs)] 'clf__estimator': [KNeighborsClassifier(**njobs)]

View file

@ -12,75 +12,6 @@ Created on Tue Mar 15 11:09:50 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [LogisticRegression(**rs)], 'clf__estimator': [LogisticRegression(**rs)],

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [MLPClassifier(**rs 'clf__estimator': [MLPClassifier(**rs

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [QuadraticDiscriminantAnalysis()] 'clf__estimator': [QuadraticDiscriminantAnalysis()]

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{'clf__estimator' : [RidgeClassifier(**rs)] {'clf__estimator' : [RidgeClassifier(**rs)]
, 'clf__estimator__alpha': [0.1, 0.2, 0.5, 0.8, 1.0] , 'clf__estimator__alpha': [0.1, 0.2, 0.5, 0.8, 1.0]

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [RandomForestClassifier(**rs 'clf__estimator': [RandomForestClassifier(**rs

View file

@ -5,31 +5,6 @@ Created on Wed May 18 06:03:24 2022
@author: tanu @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 = [ parameters = [
{ {
'clf__estimator': [SVC(**rs)] 'clf__estimator': [SVC(**rs)]

View file

@ -16,31 +16,6 @@ Created on Wed May 18 06:03:24 2022
# reg_lambda=1, scale_pos_weight=1, seed=None, silent=None, # reg_lambda=1, scale_pos_weight=1, seed=None, silent=None,
# subsample=1, verbosity=1) # 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 = [ parameters = [
{ {
'clf__estimator': [XGBClassifier(**rs , **njobs, verbose = 3)] 'clf__estimator': [XGBClassifier(**rs , **njobs, verbose = 3)]