text_html_output_1.png
from sklearn import linear_model, naive_bayes, neighbors, svm

from sklearn.base import BaseEstimator, TransformerMixin

from sklearn.metrics import classification_report

from sklearn.metrics import confusion_matrix

from typing import Tuple

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df_drug = pd.read_csv('../input/drugsets/drug200.csv')
df_drug

def find_boxplot_boundaries(
    col: pd.Series, Na_to_K_coeff: float = 1.5
) -> Tuple[float, float]:
    """Findx minimum and maximum in boxplot.

    Args:
        col: a pandas serires of input.
        Na_to_K_coeff: Na_to_K coefficient in box plot
    """
    Q1 = col.quantile(0.25)
    Q3 = col.quantile(0.75)
    IQR = Q3 - Q1
    lower = Q1 - Na_to_K_coeff * IQR
    upper = Q3 + Na_to_K_coeff * IQR
    return lower, upper

class BoxplotOutlierClipper(BaseEstimator, TransformerMixin):
    def __init__(self, Na_to_K_coeff: float = 1.5):
        self.Na_to_K = Na_to_K_coeff
        self.lower = None
        self.upper = None

    def fit(self, X: pd.Series):
        self.lower, self.upper = find_boxplot_boundaries(X, self.Na_to_K)
        return self

    def transform(self, X):
        return X.clip(self.lower, self.upper)

X_train = pd.get_dummies(X_train)
X_test = pd.get_dummies(X_test)

log_reg = linear_model.LogisticRegression(max_iter=5000)
log_reg.fit(X_train, y_train)
log_reg_acc = 100 * log_reg.score(X_test, y_test)
y_pred = log_reg.predict(X_test)
print('Logistic Regression Predictions: \n', log_reg.predict(X_test), '\n Accuracy:', log_reg_acc, '%')
print(classification_report(y_test, y_pred))
print(confusion_matrix(y_test, y_pred))