Comments (9)
@harishvk27 Is the model file human-readable or binary?
from treelite.
@harishvk27 Would it be possible to post your model file so that I can look at it?
from treelite.
it's binary.
from treelite.
@harishvk27 Also, can you check if your model can be read by XGBoost Python?
import xgboost
bst = xgboost.Booster()
bst.load_model('test.model')
To my best knowledge, Treelite uses the same loading logic as XGBoost does.
from treelite.
Thanks i could get this working.. great help indeed.
But my predictions aren't comparable to what i am seeing on python... please take a look at the attached example.
my data set file:
Feature-1.0,Feature-2.0,Feature-3.0,Classification-Type
121.0,181500.0,18.0,0.0
175.0,262500.0,26.0,0.0
197.0,295500.0,29.0,0.0
183.0,274500.0,27.0,0.0
106.0,159000.0,15.0,0.0
169.0,253500.0,25.0,0.0
127.0,190500.0,19.0,0.0
190.0,285000.0,28.0,0.0
102.0,153000.0,15.0,0.0
150.0,225000.0,22.0,0.0
1324.0,1986000.0,198.0,1.0
1667.0,2500500.0,250.0,1.0
1393.0,2089500.0,208.0,1.0
1269.0,1903500.0,190.0,1.0
1369.0,2053500.0,205.0,1.0
1285.0,1927500.0,192.0,1.0
1308.0,1962000.0,196.0,1.0
1085.0,1627500.0,162.0,1.0
1855.0,2782500.0,278.0,1.0
1536.0,2304000.0,230.0,1.0
15437.0,23155500.0,2315.0,2.0
11817.0,17725500.0,1772.0,2.0
12270.0,18405000.0,1840.0,2.0
14581.0,21871500.0,2187.0,2.0
11515.0,17272500.0,1727.0,2.0
14503.0,21754500.0,2175.0,2.0
15225.0,22837500.0,2283.0,2.0
13400.0,20100000.0,2010.0,2.0
11399.0,17098500.0,1709.0,2.0
14428.0,21642000.0,2164.0,2.0
my python code to generate model:
import pandas as pd
import sklearn
import numpy as np
import sys
from sklearn import preprocessing
import os
os.chdir('C:/Users/hkulkarni/Documents/data-sets/test')
df = pd.read_csv('test.csv')
# first 3-columns are attributes
# fourth/last column is classification-type
data_x = df[df.columns[0:3]]
data_y = df[df.columns[-1]]
from sklearn.model_selection import train_test_split
train_x, test_x, train_y, test_y = train_test_split(data_x, data_y, test_size=0.11, random_state=42)
import xgboost as xgb
xg_train = xgb.DMatrix(train_x, label=train_y)
xg_test = xgb.DMatrix(test_x, label=test_y)
param = {}
# use softmax multi-class classification
param['objective'] = 'multi:softprob'
# scale weight of positive examples
param['eta'] = 0.1
param['silent'] = 1
param['nthread'] = 1
param['num_class'] = 3
param['max_depth'] = 10
param['colsample_bytree'] = 0.7
param['alpha'] = 0.03
param['subsample'] = 0.8
watchlist = [(xg_train, 'train'), (xg_test, 'test')]
bst = xgb.train(param, xg_train, 300, watchlist, early_stopping_rounds=50)
pred = bst.predict(xg_test)
predictions = [value for value in pred]
print("test data:",test_x)
print("predictions:",predictions)
bst.save_model('xgBoostMultiClassification.model')
My result from python:
test data: Feature-1.0 Feature-2.0 Feature-3.0
27 13400.0 20100000.0 2010.0
15 1285.0 1927500.0 192.0
23 14581.0 21871500.0 2187.0
17 1085.0 1627500.0 162.0
predictions: [array([ 0.02790421, 0.0505532 , 0.92154264], dtype=float32), array([ 0.0560572 , 0.89143544, 0.05250741], dtype=float32), array([ 0.02790421, 0.0505532 , 0.92154264], dtype=float32), array([ 0.0560572 , 0.89143544, 0.05250741], dtype=float32)]
My result from C-code:
int main(int argc, char **argv)
{
union Entry my_entry[] = {
{.fvalue=13400,.missing=1},
{.fvalue=20100000,.missing=1},
{.fvalue=2010,.missing=1},
};
float result[3];
size_t len = predict_multiclass(my_entry,0,result);
printf("len:[%d]\n",len);
printf("[%lf][%lf][%lf]\n",result[0],result[1],result[2]);
}
root@ubuntu:/home/hkulkarni/treelite/tests/python/tmp/test_model# ./a.out
len:[3]
[0.910801][0.056217][0.032982]
from treelite.
Thanks! I'll take a look and get back to you.
from treelite.
@harishvk27 The C program should be revised as follows to obtain correct results:
#include <stdio.h>
#include "header.h"
int main(int argc, char **argv) {
union Entry my_entry[] = {
{.fvalue=13400},
{.fvalue=20100000},
{.fvalue=2010},
}; // do not specify missing field, since no feature is missing
float result[3];
size_t len = predict_multiclass(my_entry, 0, result);
/* Use correct format specifiers in printf() */
printf("len:[%ld]\n",len);
printf("[%f][%f][%f]\n", result[0], result[1], result[2]);
return 0;
}
Hope it helped.
from treelite.
Hats off. thanks this worked.
from treelite.
@harishvk27 how did you get this working after the runtime error? I am getting the same error.
from treelite.
Related Issues (20)
- API refactors
- Documentation for library writers HOT 1
- treelite prediction 4x slower than xgboost HOT 3
- Document that Left child is chosen when condition is evaluated True
- Use std::variant to implement type-based dispatching
- Do not call np.squeeze on output of predict_leaf() / predict_per_tree() HOT 1
- treelite::ConcatenateModelObjects() ought to set threshold_type and leaf_output_type fields
- Clean up serialization logic
- Support XGBoost gblinear Booster HOT 1
- Release version 3.3.0
- Release version 3.4.0
- Replace setup.py with pyproject.toml
- Treelite crashes with XGBoost 2.0 dev
- Document Treelite serialization format.
- Adopt Four-Document System to organize docs
- Refactor sklearn loader using mix-in classes
- Implement v4 serialization format
- Revamp JSON importer to make it easy to use
- Drop "max_index" postprocessor
- Add directory exist check in _load_lib for add_dll_directory HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from treelite.