|
|
@@ -1,10 +1,10 @@
|
|
|
package com.example.model.helper
|
|
|
|
|
|
-import java.io.{ByteArrayOutputStream, ObjectOutputStream}
|
|
|
import com.example.SparkConnect
|
|
|
import com.example.dao.{HdfsDao, ModelDao}
|
|
|
+import org.apache.spark.ml.PipelineModel
|
|
|
import org.apache.spark.ml.classification.LogisticRegressionModel
|
|
|
-import org.apache.spark.ml.{Model, PipelineModel}
|
|
|
+import org.apache.spark.ml.clustering.KMeansModel
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
|
import org.springframework.stereotype.Component
|
|
|
|
|
|
@@ -37,31 +37,35 @@ class Utils extends SparkConnect{
|
|
|
if (modelObject != null) return true
|
|
|
|
|
|
return false
|
|
|
-// val os = new ByteArrayOutputStream() // 定义一个字节数组输出流
|
|
|
-// val out = new ObjectOutputStream(os) // 对象输出流
|
|
|
-// out.writeObject(pipelineModel)
|
|
|
-// val modelByte = os.toByteArray // byte[]
|
|
|
-// var modelFile = new ModelFile() // 申明一个模型对象
|
|
|
-// modelFile.setModel(modelByte)
|
|
|
-// os.close()
|
|
|
-// out.close()
|
|
|
-// val modelFileId = modelFileDao.save(modelFile).getId
|
|
|
-// val modelOfGet = modelDao.findById(modelId)
|
|
|
-// modelOfGet.setModelPath(modelFileId.toString)
|
|
|
-// val modelObject = modelDao.save(modelOfGet)
|
|
|
-// if (modelObject != null) return true
|
|
|
-// return false
|
|
|
}
|
|
|
|
|
|
|
|
|
@throws(classOf[Exception])
|
|
|
- def storeLogisticModel(pipelineModel: LogisticRegressionModel, modelId: Int): Boolean = {
|
|
|
+ def storeLogisticModel(logisticRegressionModel: LogisticRegressionModel, modelId: Int): Boolean = {
|
|
|
val modelPath = hdfsServer + "_" + modelId + ".model"
|
|
|
|
|
|
|
|
|
hdfsDao.deleteFileInHdfs(modelPath, true)
|
|
|
|
|
|
- val flag = pipelineModel.save(modelPath)
|
|
|
+ val flag = logisticRegressionModel.save(modelPath)
|
|
|
+ val modelOfGet = modelDao.findById(modelId)
|
|
|
+
|
|
|
+ modelOfGet.setModelPath(modelPath)
|
|
|
+
|
|
|
+ val modelObject = modelDao.save(modelOfGet)
|
|
|
+ if (modelObject != null) return true
|
|
|
+
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ @throws(classOf[Exception])
|
|
|
+ def storeKMeansModel(kMeansModel: KMeansModel, modelId: Int): Boolean = {
|
|
|
+ val modelPath = hdfsServer + "_" + modelId + ".model"
|
|
|
+
|
|
|
+
|
|
|
+ hdfsDao.deleteFileInHdfs(modelPath, true)
|
|
|
+
|
|
|
+ val flag = kMeansModel.save(modelPath)
|
|
|
val modelOfGet = modelDao.findById(modelId)
|
|
|
|
|
|
modelOfGet.setModelPath(modelPath)
|