All Forums Aster
adamm313 1 post Joined 06/13
03 Jul 2013
JsonParseException error when using forest_predict

Hello,
 
I'm trying to familiarize myself with the random forest functions that come with Aster by recreating the carprices example used in the Teradata Aster Big Analytics Applicance 3H Analytics User Guide.  I am able to generate a model using forest_drive, but when I try and predict based off of the model, forest_predict returns the following error:
 

ERROR:  SQL-MR function FOREST_PREDICT failed unexpectedly.

 

The following is information that may be useful to the developer of FOREST_PREDICT:

 

com.google.gson.JsonParseException: The JsonDeserializer com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.SplitDeserializer@144aa0ce failed to deserialized json object {"leftCategories_":[1],"rightCategories_":[0],"attr_": "awd","score_":0.34285714285714286,"type_":" CLASSIFICATION_CATEGORICAL_SPLIT","leftNodeSize_":7," rightNodeSize_":5} given the type class com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.split.ClassificationSplit

        at com.google.gson.JsonDeserializerExceptionWrapper.deser ialize(JsonDeserializerExceptionWrapper.java:63)

        at com.google.gson.JsonDeserializationVisitor.invokeCusto mDeserializer(JsonDeserializationVisitor.java:88)

        at com.google.gson.JsonDeserializationVisitor.visitUsingC ustomHandler(JsonDeserializationVisitor.java:76)

        at com.google.gson.ObjectNavigator.accept(ObjectNavigator .java:98)

        at com.google.gson.JsonDeserializationContextDefault.from JsonObject(JsonDeserializationContextDefault.java:73)

        at com.google.gson.JsonDeserializationContextDefault.dese rialize(JsonDeserializationContextDefault.java:51)

        at com.google.gson.Gson.fromJson(Gson.java:495)

        at com.google.gson.Gson.fromJson(Gson.java:465)

        at com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.NodeDeserializer.deserialize(NodeDese rializer.java:94)

        at com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.NodeDeserializer.deserialize(NodeDese rializer.java:33)

        at com.google.gson.JsonDeserializerExceptionWrapper.deser ialize(JsonDeserializerExceptionWrapper.java:50)

        at com.google.gson.JsonDeserializationVisitor.invokeCusto mDeserializer(JsonDeserializationVisitor.java:88)

        at com.google.gson.JsonDeserializationVisitor.visitUsingC ustomHandler(JsonDeserializationVisitor.java:76)

        at com.google.gson.ObjectNavigator.accept(ObjectNavigator .java:98)

        at com.google.gson.JsonDeserializationContextDefault.from JsonObject(JsonDeserializationContextDefault.java:73)

        at com.google.gson.JsonDeserializationContextDefault.dese rialize(JsonDeserializationContextDefault.java:51)

        at com.google.gson.Gson.fromJson(Gson.java:495)

        at com.google.gson.Gson.fromJson(Gson.java:465)

        at com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.NodeDeserializer.deserialize(NodeDese rializer.java:93)

        at com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.NodeDeserializer.deserialize(NodeDese rializer.java:33)

        at com.google.gson.JsonDeserializerExceptionWrapper.deser ialize(JsonDeserializerExceptionWrapper.java:50)

        at com.google.gson.JsonDeserializationVisitor.invokeCusto mDeserializer(JsonDeserializationVisitor.java:88)

        at com.google.gson.JsonDeserializationVisitor.visitUsingC ustomHandler(JsonDeserializationVisitor.java:76)

        at com.google.gson.ObjectNavigator.accept(ObjectNavigator .java:98)

        at com.google.gson.JsonDeserializationContextDefault.from JsonObject(JsonDeserializationContextDefault.java:73)

        at com.google.gson.JsonDeserializationContextDefault.dese rialize(JsonDeserializationContextDefault.java:51)

        at com.google.gson.Gson.fromJson(Gson.java:495)

        at com.google.gson.Gson.fromJson(Gson.java:465)

        at com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.TreeSerializer.deserializeClassificat ionTree(TreeSerializer.java:94)

        at com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.TreeSerializer.deserializeTree(TreeSe rializer.java:48)

        at com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.forest_predict.grabForestFromTable(fo rest_predict.java:440)

        at com.asterdata.sqlmr.analytics.predictive_modeling.deci sion_tree.forest.forest_predict.operateOnSomeRows(fore st_predict.java:202)

        at com.asterdata.ncluster.sqlmr.internal.SwigRunner.runOp eratingOnRows(SwigRunner.java:432)

        at com.asterdata.ncluster.sqlmr.internal.SwigRunner.runOp eratingTask(SwigRunner.java:361)

        at com.asterdata.

 

 

Here are the function calls and create table statements that I used (basically what is in the user guide):

 

 

select * from forest_drive(

on (select 1)

partition by 1

userid('db_superuser')

password('db_superuser')

inputTable('tutorial.forest_carprices')

outputTable('tutorial.forest_carprices_model')

treetype('classification')

response('price_class')

numericInputs('cylinders','horsepower','city_mpg',' highway_mpg',

'weight','wheelbase','length','width')

categoricalInputs('sports','suv','wagon','minivan',' pickup',

'awd','rwd')

maxdepth(4)

minnodesize(5)

variance(0.05)

numTrees(10)

);

 

 

select test_id as car_name, prediction as predicted_class

from forest_predict(

on tutorial.forest_carprices_predict

userid('db_superuser')

password('db_superuser')

forest('tutorial.forest_carprices_model')

numericInputs('cylinders','horsepower','city_mpg',' highway_mpg',

'weight','wheelbase','length','width')

categoricalInputs('sports','suv','wagon','minivan',' pickup',

'awd','rwd')

idcol('car_name')

);

 

 

CREATE TABLE tutorial.forest_carprices (

car_name varchar(100) NOT NULL,

sports varchar(5) NULL,

suv varchar(5) NULL,

wagon varchar(5) NULL,

minivan varchar(5) NULL,

pickup varchar(5) NULL,

awd varchar(5) NULL,

rwd varchar(5) NULL,

engine integer NULL,

cylinders smallint NULL,

horsepower smallint NULL,

city_mpg smallint NULL,

highway_mpg smallint NULL,

weight integer NULL,

wheelbase smallint NULL,

[length] smallint NULL,

[width] smallint NULL,

retail_price integer NULL,

dealer_price integer NULL,

price_class smallint NULL

)

DISTRIBUTE BY HASH (weight)

STORAGE ROW;

 

 

 

CREATE TABLE tutorial.forest_carprices_predict (

car_name varchar(100) NOT NULL,

sports varchar(5) NULL,

suv varchar(5) NULL,

wagon varchar(5) NULL,

minivan varchar(5) NULL,

pickup varchar(5) NULL,

awd varchar(5) NULL,

rwd varchar(5) NULL,

engine integer NULL,

cylinders smallint NULL,

horsepower smallint NULL,

city_mpg smallint NULL,

highway_mpg smallint NULL,

weight integer NULL,

wheelbase smallint NULL,

[length] smallint NULL,

[width] smallint NULL,

retail_price integer NULL,

dealer_price integer NULL

)

DISTRIBUTE BY HASH (weight)

STORAGE ROW;

 

 

Any insight into what caused this error would be appreciated!

 

Thanks,

 

Adam

Ji Zeng 1 post Joined 06/13
25 Jul 2013

the json data is not correct.
"leftCategories_" 's values is [1] , but [1] is not a correct value.
" rightCategories_" 's values is [0] , but [0] is not a correct value.

xhudik 4 posts Joined 04/13
08 Sep 2013

@Ji Zeng, unfortunately it seems json is correct. Try http://jsonlint.com/. Also my json perl  validator doesn't protest.

You must sign in to leave a comment.