Skip to content

Instantly share code, notes, and snippets.

View sergey-lebedev's full-sized avatar

Sergey sergey-lebedev

  • Saint-Petersburg
View GitHub Profile
@ytsaig
ytsaig / custom_softmax.py
Created June 6, 2017 07:29
Multiclass classification (softmax regression) via xgboost custom objective
import numpy as np
from sklearn import datasets
from sklearn.metrics import confusion_matrix
from sklearn.preprocessing import OneHotEncoder
import xgboost as xgb
def softmax(z):
z -= np.max(z)
sm = (np.exp(z).T / np.sum(np.exp(z), axis=1)).T