2014-12-15 4 views
1

나는 LinearRegressionWithSGD을 사용하고 있으며 모델 가중치와 절편을 저장합니다. 나는이 순간을 위해 무시 될 수 있도록 절편을 설정하지 않는 기차를 사용하고 있기 때문에MLLIb : 모델 저장 및로드

1.20455 
0.1356 
0.000456 

절편이 0 : 가중치를 포함

파일이 형식을 가지고있다. 이제 새 모델 객체를 초기화하고 위의 파일에서 저장된 가중치를 사용하려고합니다. 우리는이 라인을 따라 CDH 5.1을

뭔가를 사용 :

// Here is the code the load data and train the model on it. 
val weights = sc.textFile("linear-weights"); 
val model = new LinearRegressionWithSGD(weights); 

후 사용

은이다 : 나는 그렇게 할 방법

// Here is where I want to use the trained model to predict on new data. 
val valuesAndPreds = testData.map { point => 
    // Predicting on new data. 
    val prediction = model.predict(point.features) 
    (point.label, prediction) 
} 

모든 포인터?

답변

1

LibSVM 파일을 입력으로 사용하는 LinearRegressionWithSGD의 교육 부분을 복제하는 것으로 보입니다.

  • 교육 단계에서 라이브러리가 작업을 수행하는 대신 자신 만의 가중치를 제공하고 싶습니까?

    // Stick in your weights below .. 
    var model = algorithm.createModel(weights, 0.0) 
    
    // Now you can run the last steps of the 'normal' process 
    val prediction = model.predict(test.map(_.features)) 
    val predictionAndLabel = prediction.zip(test.map(_.label)) 
    
    :
  • 그렇다면, 당신은

여기 단계는 이미 원하는 가중치를 계산 한 주어질 것/수행 훈련을 자신의 방법을 createModel을 자신의 LinearRegressionWithSGD를 작성하고 대체 할 수 있습니다

여기를 참조하려면 교육 단계가 포함 된 '표준'접근 방법이 있습니다.

val data = MLUtils.loadLibSVMFile(sc, inputFile).cache() 

val splits = examples.randomSplit(Array(0.8, 0.2)) 
val training = splits(0).cache() 
val test = splits(1).cache() 

val updater = params.regType match { 
    case NONE => new SimpleUpdater() 
    case L1 => new L1Updater() 
    case L2 => new SquaredL2Updater() 
} 

val algorithm = new LinearRegressionWithSGD() 

val algorithm = new LinearRegressionWithSGD() 
algorithm.optimizer 
    .setNumIterations(params.numIterations) 
    .setStepSize(params.stepSize) 
    .setUpdater(updater) 
    .setRegParam(params.regParam) 

val model = algorithm.run(training) 

val prediction = model.predict(test.map(_.features)) 
val predictionAndLabel = prediction.zip(test.map(_.label))