scikit-learn : ValueError: 没有足够的值来解包(预期 2,得到 1) [英] scikit-learn : ValueError: not enough values to unpack (expected 2, got 1)

查看:51
本文介绍了scikit-learn : ValueError: 没有足够的值来解包(预期 2,得到 1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最新版本的 sklearn 中有一个 check_array 函数用于计算 平均绝对百分比误差 (MAPE) 但它似乎没有以与以前版本相同的方式工作.

There is a check_array function for calculating mean absolute percentage error (MAPE) in the recent version of sklearn but it doesn't seem to work the same way as the previous version.

import numpy as np
from sklearn.utils import check_array

def calculate_mape(y_true, y_pred): 
    y_true, y_pred = check_array(y_true, y_pred)

    return np.mean(np.abs((y_true - y_pred) / y_true)) * 100
y_true = [3, -0.5, 2, 7]; y_pred = [2.5, -0.3, 2, 8]
calculate_mape(y_true, y_pred)

这是返回一个错误:ValueError: not enough values to unpack (expected 2, got 1).这个错误有什么解决办法吗?

This is returning an error: ValueError: not enough values to unpack (expected 2, got 1). Is there any fix for this error?

推荐答案

看来

check_array

返回单个对象

查看文档此处

这篇关于scikit-learn : ValueError: 没有足够的值来解包(预期 2,得到 1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆