Sorry, I had a mistake in my example code. I thought the model would be
stored as a (Option[DataSet[Factors]], Option[DataSet[Factors]]) but
instead it’s stored as Option[(DataSet[Factors], DataSet[Factors])].

So the code should be

val als = ALS()

als.fit(input)

val alsModelOpt = als.factorsOption

val factorsTypeInfo = TypeInformation.of(classOf[Factors])
val factorsSerializer = factorsTypeInfo.createSerializer(new ExecutionConfig())
val outputFormat = new TypeSerializerOutputFormat[Factors]
outputFormat.setSerializer(factorsSerializer)

alsModelOpt match {
    case Some((userFactors, itemFactors)) =>
        userFactors.write(outputFormat, "user_path")
        itemFactors.write(outputFormat, "item_path")
    case None =>
}

if I’m not mistaken.

If you don’t see any output, then it might be the case that your model is
empty. Could you check that? You could for example simply call print on the
model DataSet.

Do you call env.execute at the end of your program? If you don’t do that,
then the job is not executed.

Cheers,
Till
​

On Tue, Apr 12, 2016 at 1:25 PM, KirstiLaurila <kirsti.laur...@rovio.com>
wrote:

> Hi,
>
> those parts were examples how I had tried. I tried with your suggestions,
> but still no success. Additionally,
> there were some problems:
>
>
> val (userFactorsOpt, itemFactorsOpt) = als.factorsOption
>
> If I had just this, userFactorsOpt And itemFactorsOpt did not have write
> method. So I added get there i.e.
>
> val (userFactorsOpt, itemFactorsOpt) = als.factorsOption.get
>
>
> val factorsTypeInfo = TypeInformation.of(classOf[Factors])
> val factorsSerializer = factorsTypeInfo.createSerializer(new
> ExecutionConfig())
> val outputFormat = new TypeSerializerOutputFormat[Factors]
>
>
> Here, the factorsSerializer was not used at all, so I guess this was
> missing
> line
>
>     outputFormat.setSerializer(factorsSerializer)
>
>
> userFactorsOpt match {
>     case Some(userFactors) => userFactors.write(outputFormat, "user_path")
>     case None =>
> }
>
>
> This doesn't run because of error message
>
> Error:(71, 12) constructor cannot be instantiated to expected type;
>  found   : Some[A]
>  required:
>
> org.apache.flink.api.scala.DataSet[org.apache.flink.ml.recommendation.ALS.Factors]
>       case Some(userFactors) => userFactorsOpt.write(outputFormat,
> "path_to_my_file")
>
> However, I still tried not to have match case i.e.
>
>     userFactorsOpt.write(outputFormat, "path")
>
> but nothing was written anywhere.
>
>
>
>
>
> --
> View this message in context:
> http://apache-flink-user-mailing-list-archive.2336050.n4.nabble.com/Flink-ML-1-0-0-Saving-and-Loading-Models-to-Score-a-Single-Feature-Vector-tp5766p6059.html
> Sent from the Apache Flink User Mailing List archive. mailing list archive
> at Nabble.com.
>

Reply via email to