Merge pull request #965 from shaform/fs

Support the cases when user load dataset and save model to two different file systems
This commit is contained in:
Nan Zhu 2016-03-11 09:25:02 -05:00
commit 8e3ce908fe
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()
}