
156
|
第
5
章
/* 构造线性估计器 */
LinearModelEstimator estimator =
new
LinearModelEstimator(
new
LinearModel(4, 3,
new
SoftmaxOutputFunction()),
new
SoftMaxCrossEntropyLossFunction(),
new
DeltaRule(0.001));
estimator.setBatchSize(0);
estimator.setMaxIterations(6000);
estimator.setTolerance(10E-6);
/* 模型参数的学习 */
estimator.learn(resampler.getTrainingFeatures(), resampler.getTrainingLabels());
/* 根据测试数据进行预测 */
RealMatrix prediction = estimator.predict(resampler.getTestingFeatures());
/* 结果 */
ClassifierAccuracy accuracy =
new
ClassifierAccuracy(prediction,
resampler.getTestingLabels());
estimator.isConverged(); // true
estimator.getNumIterations(); ...