예제 #1
0
def get_results(X):
    categoricals = X.select_dtypes(include='object')
    categoricals = categoricals.astype(str)
    categoricals = categoricals.apply(label.fit_transform)
    label_encoding = categoricals['country']
    categoricals.drop(['country'], axis=1, inplace=True)
    X_one = enc.transform(categoricals)
    encoded_data = pd.DataFrame(X_one.todense())
    encoded_data.reset_index(drop=True, inplace=True)
    categoricals.reset_index(drop=True, inplace=True)

    original_numeric = X.select_dtypes(include='number')
    original_numeric.reset_index(drop=True, inplace=True)

    X = pd.concat([original_numeric, encoded_data, label_encoding],
                  axis=1).values
    Xp = pca.transform(X)

    clf = XGBClassifier()
    booster = Booster()
    booster.load_model('xgb.model')
    clf._Booster = booster
    classes = clf.predict_proba(Xp)
    y_pred = [0 if c[0] > 0.5 else 1 for c in classes]

    return y_pred
예제 #2
0
    def analyze(self, event):
        array_list = [
            "lepJet_llpdnnx_-1_isLLP_QMU_QQMU",
            "lepJet_llpdnnx_0_isLLP_QMU_QQMU",
            "lepJet_llpdnnx_1_isLLP_QMU_QQMU",
            "lepJet_llpdnnx_2_isLLP_QMU_QQMU", "dimuon_mass", "dimuon_deltaR",
            "lepJet_pt", "lepJet_eta", "lepJet_deltaR", "MET_pt", "MET_phi",
            "looseMuons_pt", "looseMuons_eta", "looseMuons_dxy",
            "tightMuons_pt", "tightMuons_eta", "tightMuons_dxy"
        ]
        data = pd.DataFrame(data={
            "lepJet_llpdnnx_-1_isLLP_QMU_QQMU":
            getattr(event, "lepJet_llpdnnx_-1_isLLP_QMU_QQMU"),
            "lepJet_llpdnnx_0_isLLP_QMU_QQMU":
            event.lepJet_llpdnnx_0_isLLP_QMU_QQMU,
            "lepJet_llpdnnx_1_isLLP_QMU_QQMU":
            event.lepJet_llpdnnx_1_isLLP_QMU_QQMU,
            "lepJet_llpdnnx_2_isLLP_QMU_QQMU":
            event.lepJet_llpdnnx_2_isLLP_QMU_QQMU,
            "dimuon_mass":
            event.dimuon_mass,
            "dimuon_deltaR":
            event.dimuon_deltaR,
            "lepJet_pt":
            event.lepJet_pt,
            "lepJet_eta":
            event.lepJet_eta,
            "lepJet_deltaR":
            event.lepJet_deltaR,
            "MET_pt":
            event.MET_pt,
            "MET_phi":
            event.MET_phi,
            "looseMuons_pt":
            event.looseMuons_pt,
            "looseMuons_eta":
            event.looseMuons_eta,
            "looseMuons_dxy":
            event.looseMuons_dxy,
            "tightMuons_pt":
            event.tightMuons_pt,
            "tightMuons_eta":
            event.tightMuons_eta,
            "tightMuons_dxy":
            event.tightMuons_dxy,
        },
                            columns=array_list,
                            index=[0])

        model = XGBClassifier()
        booster = Booster()
        #model._le = LabelEncoder().fit([1])
        booster.load_model(self.modelPath)
        booster.feature_names = array_list
        model._Booster = booster
        bdt_score = model.predict_proba(data)
        setattr(event, "bdt_score", bdt_score[:, 1])
        return True
예제 #3
0
from xgboost import XGBClassifier, Booster
model = XGBClassifier()
booster = Booster()
booster.load_model('model.pkl')
model._Booster = booster

print(model.predict([[0, 0, 0, 0, 0, 00]]))
예제 #4
0
def load_model(model_path):
    clf = XGBClassifier()
    booster = Booster()
    booster.load_model(model_path)
    clf._Booster = booster
    return clf
예제 #5
0
from sklearn.preprocessing import LabelEncoder

from process_data import process_input

# For logging
import logging
import traceback
from logging.handlers import RotatingFileHandler
from time import strftime, time

app = Flask(__name__)

xgb_ClaimInd_model = XGBClassifier()
booster = xgb.Booster()
booster.load_model('models/xgb_ClaimInd_model')
xgb_ClaimInd_model._Booster = booster

xgb_ClaimInd_model._le = LabelEncoder().fit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

# Logging
handler = RotatingFileHandler('app.log', maxBytes=100000, backupCount=5)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(handler)


@app.route("/")
def index():
    return "RenataTNT API"