#3221·darts

当 gridsearch() 返回的参数组合在网格中排名第一时,它会返回一个 NaN 评分的参数组合作为最佳结果

作者: shaurya416创建于 2026年9月28日更新于 2026年9月29日

darts/models/forecasting/forecasting_model.py:2033

python
        errors: list[float] = _parallel_apply(
            iterator, _evaluate_combination, n_jobs, {}, {}
        )

        min_error = min(errors)

        best_param_combination = dict(
            list(zip(parameters.keys(), params_cross_product[errors.index(min_error)]))
        )

With NaN in the list, Python's min() depends on order. x < nan is always False, so a NaN in position 0 is never replaced, while a NaN anywhere else is skipped: min([nan, 5.0, 0.3]) is nan but min([5.0, nan, 0.3]) is 0.3. The docstring (L1692) says "the model resulting in the smallest metric output will be chosen". In practice, whenever the first evaluated combination scores NaN, gridsearch returns that combination with min_error=nan, whatever the other scores are.