我正在使用数据集训练 ALS 模型。我正在尝试保存此模型并稍后检索它并使用它来获得预测。我可以保存模型,但在尝试检索它时出现错误 IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.mapred.FileInputFormat
.
我的代码如下:
MatrixFactorizationModel model;
MatrixFactorizationModel sameModel;
int rank = 10;
int numIterations = 10;
model = ALS.train( JavaRDD.toRDD( ratings ), rank, numIterations, 0.01 );
model.save( sc.sc(), "src/main/resources/UserBasedModel" );
sameModel = MatrixFactorizationModel.load( sc.sc(), "src/main/resources/UserBasedModel" );
堆栈跟踪如下:
我该如何解决这个问题?感谢您的帮助。
最佳答案
将 Hadoop 版本设置为 2.7.2 解决了问题。
如 here 中 SO 问题的答案中所述该错误是由于 Hadoop 和 Guava 版本不匹配导致的。 Guava 17.0以上版本,必须使用Hadoop 2.7.2。
关于java - 如何使用 Spark - Java 检索保存的 ALS 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41134929/