我收到的结果是Int类型,如何获取Apache Spark Mllib ALS推荐系统的String类型的userId?

问题描述

Dataset <Row> ds = spark.read()
  .option("header",false)
  .option("inferSchema",true)
  .csv("results.csv")

  .toDF("artistname","userid","rate");

ds.show();

StringIndexer stringindexer = new StringIndexer()
  .setInputCol("artistname")
  .setoutputCol("artistnameindex");

StringIndexer stringindexer1 = new StringIndexer()
  .setInputCol("userid")
  .setoutputCol("useridindex");

StringIndexerModel model = stringindexer.fit(ds);

StringIndexerModel model1 = stringindexer1.fit(ds);

ds = model.transform(ds);
ds.show();

ds = model1.transform(ds);

ds.show();

//toDF("userId","courseId","proportionWatched");

ALS als = new ALS()
  .setMaxIter(10)
  .setRegParam(0.1)
  .setItemCol("artistnameindex")
  .setUserCol("useridindex")
  .setratingCol("rate");

ALSModel alsmodel = als.fit(ds);

Dataset <Row> result = alsmodel.recommendForAllUsers(5);

建议的Apache Spark Mllib库不接受字符串类型,因此出于这些原因我使用StringIndexer,但是结果为int类型,因此我希望将结果归为字符串类型,因为我的数据框userIds为String类型,我如何获取我的结果字符串类型

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)