Any way to read saved models?

User 761 | 12/9/2014, 7:07:34 AM

Hey is there any way to read a saved model or convert it to human readable form? For example : Get all the coefficients of a logistic regression model in order to use that final objective function somewhere else outside of graph lab. When I open the objects.bin file it gets converted to objects.bin.cpgz and when I unzip that it gets converted back to a new objects.bin. An endless loop.

I looked at the following thread from March http://forum.graphlab.com/discussion/71/can-the-recommender-system-model-be-saved-as-pmml/p1 Are there any plans for adding PMML support?

Comments

User 91 | 12/9/2014, 7:14:11 AM

Mihir,

You can save the coefficients of the model as an SFrame in csv format. model['coefficients'].save('foo.csv', format='csv')

which can then be read from another program. Does that work for you?


User 761 | 12/9/2014, 10:16:32 AM

Yeah that's perfect for Regression. But is there any way to do that with boostedtreesclassifier Like a way to use the model through Java

Basically I'm making the boosted_trees model using Graphlab. But there are some some reasons due to which when it comes to deploying it I'm not allowed to use Python but instead need to use some kind of Java wrapper around it.

PS I'd just like to point out the awesome and prompt support that you guys are giving on this forum. Much appreciated :D


User 761 | 12/9/2014, 10:25:38 AM

I can see all the trees in model['json_trees'] but I'm not sure how exactly I can use them in a convenient way


User 10 | 12/9/2014, 6:15:33 PM

Hey Mihir -

Have you taken a look at GraphLab Predictive Services yet? With Predictive Services, a cluster of EC2 machines can be spun up to host Predictive Objects (ex Boosted Trees Model) with a REST API. This way client applications, written in any language, can easily query the Predictive Objects. Does this help with the use case you describe?

We recently published a Notebook introducing the APIs for Predictive Services, available here: http://graphlab.com/learn/gallery/notebooks/predictiveservicesintro.html

And we have more documentation about Predictive Services in the User Guide, here: http://graphlab.com/learn/userguide/index.html#DeploymentGraphLabPredictive_Services

We also offer a Python client library (GraphLab-Service-Client), which is based on libcurl, to query Predictive Services. We will be adding more languages soon (including Java), but it should be easy to build a quick wrapper in Java to query Predictive Services.

Here is a code snippet for how to query a Boosted Trees Model using Predictive Services:

<pre class="CodeBlock"><code>import graphlab url = 'http://s3.amazonaws.com/gl-testdata/xgboost/mushroom.csv' data = graphlab.SFrame.readcsv(url) data['label'] = (data['label'] == 'p') train, test = data.randomsplit(0.8) model = graphlab.boostedtreesclassifier.create(train, target='label')

list my predictive services

graphlab.deploy.predictiveservices ps = graphlab.deploy.predictiveservices[0] # loads the 1st predictive service by index in the listing

add a new predictive object using this Gradient Boosted Tree Classifier Model

ps.add('rajat-gbmtest', model) ps.apply_changes()

d = test[0] # this just gets the first row of the test SFrame as a dict

To query the model in the Predictive Service, need to provide a list of dict type, each entry being the dict for the row in the SFrame

so to create a list of dict type could do the following

all_data = [ t for t in test ]

and now the actual query, the method name is classify, like the following:

ps.query('rajat-gbmtest', {'method':'classify', 'data':{'dataset':[d]}}) </code></pre>

Hope this helps, let me know if I can help further.

Rajat


User 761 | 12/10/2014, 4:51:47 PM

Is there a trial period where we can test the predictive services before purchasing?


User 46 | 12/11/2014, 6:25:39 PM

Hi Mihir,

Predictive services are free to try through the end of the year after which we offer some free hours.

After Jan 1, the free subscription (Discover) gives you 30 hours free to use any of our deployment tools. If you upgrade to Develop or Deploy, you get 30 hours free/month. You can use this time as you please.

For reference, our pricing & subscription plans are here: <a href="http://graphlab.com/products/create/purchase-plans.html">http://graphlab.com/products/create/purchase-plans.html</a>

We'd love to hear what you're building. If you need more time than the above or have any questions, we'd be happy to chat. Just email <a href="mailto: contact@graphlab.com">contact@graphlab.com</a>.

Good luck!

Shawn