support different types of filesystems

This commit is contained in:
Shaform 2016-03-11 21:44:59 +08:00
parent 00e7e4eef0
commit 6558ef3273
2 changed files with 4 additions and 2 deletions

View File

@ -129,7 +129,8 @@ object XGBoost extends Serializable {
* @return The loaded model
*/
def loadModelFromHadoop(modelPath: String)(implicit sparkContext: SparkContext): XGBoostModel = {
val dataInStream = FileSystem.get(sparkContext.hadoopConfiguration).open(new Path(modelPath))
val path = new Path(modelPath)
val dataInStream = path.getFileSystem(sparkContext.hadoopConfiguration).open(path)
val xgBoostModel = new XGBoostModel(SXGBoost.loadModel(dataInStream))
xgBoostModel
}

View File

@ -50,7 +50,8 @@ class XGBoostModel(booster: Booster)(implicit val sc: SparkContext) extends Seri
* @param modelPath The model path as in Hadoop path.
*/
def saveModelToHadoop(modelPath: String): Unit = {
val outputStream = FileSystem.get(sc.hadoopConfiguration).create(new Path(modelPath))
val path = new Path(modelPath)
val outputStream = path.getFileSystem(sc.hadoopConfiguration).create(path)
booster.saveModel(outputStream)
outputStream.close()
}