2017-08-04 3 views
0

Ich habe ein Problem beim Laden des gespeicherten Scala XGBoost-Modells aus AWS S3. Unten ist mein Code. Das Problem ist, dass ich das Scala XGBoost-Modell in AWS S3 speichern kann, das Modell aber nicht von AWS S3 laden kann.Problem beim Laden des gespeicherten Scala XGBoost-Modells aus AWS S3

val trainingData = sqlContext.read.parquet(path1) 

val testData = sqlContext.read.parquet(path2) 

val OOTvalData = sqlContext.read.parquet(path3) 

// number of iterations 
val numRound = 200 
val numWorkers = 4 
// training parameters 
val paramMap = List("eta" -> 0.023f,"max_depth" -> 6,"min_child_weight" -> 3.0,"subsample" -> 1.0,"colsample_bytree" -> 0.82,"colsample_bylevel" -> 0.9,"base_score" -> 0.005,"eval_metric" -> "auc","seed" -> 8,"silent" -> 1,"objective" -> "binary:logistic").toMap 

println("Starting Xgboost ") 

val xgBoostModelWithDF = XGBoost.trainWithDataFrame(path1, paramMap, round = numRound, nWorkers = numWorkers, useExternalMemory = true) 

xgBoostModelWithDF.write.overwrite().save(path4) 


#### I am getting error at the below step to load the model from S3 location 
xgBoostModelWithDF1 = XGBoost.load(path4) 
+0

, was der Fehler, den Sie bekommen? – jamborta

+0

Ich bekomme den Fehler - Fehler: Wert laden ist kein Mitglied des Objekts ml.dmlc.xgboost4j.scala.spark.XGBoost. Ich suche nach einer anderen Option zum Laden. – harry

Antwort

0

Ich arbeite mit Python und ich mache 2 Dinge, die Sie nicht tun.

  1. ich das Objekt von S3 gelesen und verwenden .lesen() Dann habe ich es in Pythons bytearray
  2. ich initialisieren auch einen Booster.

Hier ist das Python-Beispiel Hoffnung können Sie es in Scala verwandeln

import xgboost as xgb 

# reading model from s3 (you do it your way) 
prev_xgb_model = s3_handler.get_gzip_file_content(reading_last_model_key) 

# use .read() and transform it into pythons bytearray 
model_ba = bytearray(prev_xgb_model.read()) 

# initilizing a model 
prev_model = xgb.Booster({'nthread': 4}) 

# loading the model 
prev_model.load_model(model_ba) 
Verwandte Themen