remove ClfSwitcher() from this lot
This commit is contained in:
parent
18d9b77aee
commit
1a1154b4f4
15 changed files with 0 additions and 419 deletions
|
@ -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)],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue