我想知道构建模型所需的时间。但是,当多次运行算法来构建模型时,我花了很多时间来构建模型。为什么不同?为什么不用固定的时间来构建模型呢?即使同一算法的时间波动,我如何比较两个不同的算法所用的时间。
Double start_time=System.nanoTime()/Math.pow(10, 9);
KMeansModel clusters = KMeans.train(rdd.rdd(), numClusters,numIterations,init_mode,30);
System.out.println("time taken to build model: "+((System.nanoTime()/Math.pow(10, 9)) - start_time));发布于 2020-11-28 18:42:40
您可以将模型训练时间度量为多次运行的平均值。例如,运行100次训练,并取总时间/ 100。假设算法在训练过程中不使用太多的随机性,这应该会在运行之间提供更一致的值(作为批处理)。
如果您正在使用spark,启用spark的loginfo来查看每次运行的统计数据可能会很有用。对于kmeans,您应该在其他方面看到:
logInfo(f"Initialization with $initializationMode took $initTimeInSeconds%.3f seconds.")
logInfo(f"Iterations took $iterationTimeInSeconds%.3f seconds.")
logInfo(s"KMeans converged in $iteration iterations.")https://stackoverflow.com/questions/65048361
复制相似问题