Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meet error when load xgboost model which trained with the API in sklearn #56

Open
frontword opened this issue Apr 8, 2019 · 1 comment

Comments

@frontword
Copy link

frontword commented Apr 8, 2019

leaves does not support the sklearn xgboost model ?
I use the below python code to train one xgboost model, meet error when use the below API to load this model in go code
leaves.XGEnsembleFromFile("xg_iris.model", false)


The error :
mark@mark:~/golang $ go run predict_iris.go
Name: xgboost.gbtree
NFeatures: 4
NOutputGroups: 3
NEstimators: 100
panic: different sizes: len(a) = 30, len(b) = 90

goroutine 1 [running]:
main.main()
/home/mark/golang/predict_iris.go:44 +0x686
exit status 2


Below is the python code to train the xgboost model using the xgboost API in sklearn:
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
import xgboost as xgb
from xgboost.sklearn import XGBClassifier

X, y = datasets.load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

xg_train = xgb.DMatrix(X_train, label=y_train)
xg_test = xgb.DMatrix(X_test, label=y_test)
params = {
'objective': 'multi:softmax',
'num_class': 3,
}
n_estimators = 5
#clf = xgb.train(params, xg_train, n_estimators)
clf = XGBClassifier(**params)
clf = clf.fit(X_train, y_train)
y_pred = clf.predict_proba(X_test)[:,1]
clf.save_model('xg_iris.model')
np.savetxt('xg_iris_true_predictions.txt', y_pred, delimiter='\t')
datasets.dump_svmlight_file(X_test, y_test, 'iris_test.libsvm')

@dmitryikh
Copy link
Owner

@frontword , thank you for your detailed feedback.

leaves does not support the sklearn xgboost model ?

Currently, models generated from xgboost sklearn API are not tested. I thought, that xgboost sklearn API produces the same models as xgboost python API.

I will check you case and will come back yo you soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants