# RandomForest Model load error

**URL:** <https://discuss.elastic.co/t/randomforest-model-load-error/32093>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [October 13, 2015, 2:26pm UTC](https://discuss.elastic.co/t/randomforest-model-load-error/32093 "2015-10-13T14:26:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sar82](https://avatars.discourse-cdn.com/v4/letter/s/8491ac/32.png) [@Sar82](https://discuss.elastic.co/u/Sar82)\
**Post date:** [October 13, 2015, 2:26pm UTC](https://discuss.elastic.co/t/randomforest-model-load-error/32093/1 "2015-10-13T14:26:54Z")

</div>

My Spark program reads data from ElasticSearch(in JavaPairRDD\<String, Map\<String, Object\>\> form). This JavaPairRDD is converted to JavaRDD using following inner class

static class Transformer implements  
Function\<Tuple2\<String, Map\<String, Object\>\>, LabeledPoint\> {  
@Override  
public LabeledPoint call(Tuple2\<String, Map\<String, Object\>\> arg0)  
throws Exception {  
HashingTF tf = new HashingTF();  
Map\<String, Object\> map = (Map\<String, Object\>) arg0.\_2();

```
		// get values from Map
		Set<String> keys = map.keySet();
		List<Object> valuesList = new ArrayList<Object>();
		for (Iterator<String> i = keys.iterator(); i.hasNext();) {
			String key = (String) i.next();
			Object value = (Object) map.get(key);
			valuesList.add(value);
		}
		return new LabeledPoint(1d, tf.transform(valuesList));
	}
}

```

Using JavaRDD data RandomForest Model is generated and saved to the specific location on the same machine. Model gets saved successfully.

But while loading the model I am getting following exception,  
java.lang.reflect.InvocationTargetException  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:497)  
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)  
at java.lang.Thread.run(Thread.java:745)  
Caused by: org.json4s.package$MappingException: Did not find value which can be converted into java.lang.String  
at org.json4s.reflect.package$.fail(package.scala:96)  
at org.json4s.Extraction$.convert(Extraction.scala:554)  
at org.json4s.Extraction$.extract(Extraction.scala:331)  
at org.json4s.Extraction$.extract(Extraction.scala:42)  
at org.json4s.ExtractableJsonAstNode.extract(ExtractableJsonAstNode.scala:21)  
at org.apache.spark.mllib.tree.model.DecisionTreeModel$.load(DecisionTreeModel.scala:326)  
at org.apache.spark.mllib.tree.model.DecisionTreeModel.load(DecisionTreeModel.scala)  
at co.nttd.integration.SparkESIntegration.main(SparkESIntegration.java:96)

---

<div class="post-metadata">

**Author:** ![costin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/costin/32/44950_2.png) [@costin](https://discuss.elastic.co/u/costin)\
**Post date:** [October 20, 2015, 4:51pm UTC](https://discuss.elastic.co/t/randomforest-model-load-error/32093/2 "2015-10-20T16:51:54Z")

</div>

Unfortunately you are likely to find better answers on the Spark list directly mainly because the code posted as well as the stacktrace is Spark specific (in this case through json4s which is a JSON library for Scala that seems to be invoked from Spark).

If you can debug (or enable logging) to see what's the underlying json - it looks like the returned json doesn't match the data model. Since all libraries are open-source you can easily track down the source and get additional insights into the code execution.

Hope this helps,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:27pm UTC](https://discuss.elastic.co/t/randomforest-model-load-error/32093/3 "2017-07-06T13:27:20Z")

</div>


