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 library for reccomendation不接受字符串类型,因此我使用了stringindexer,但是结果是int类型的,因此我希望结果是字符串类型的,因为我的dataframe userid是字符串类型的。如何才能以字符串类型返回结果
暂无答案!
目前还没有任何答案,快来回答吧!