为什么我在 pyhton 统计中得到一个“int”对象不可迭代错误?

问题描述

所以我正在使用 python jupyter 进行学校练习,我应该编写一个函数,该函数从两个整数或浮点数(Iguess)列表(列表是参数 x 和 y)中计算回归系数。所以我写了代码,当我运行它时,我得到一个 TypeError: 'int' object is not iterable。而且我知道有很多关于这个特定错误主题,但我找不到自己的解决方案,因为 x 和 y 只包含整数列表,所以我不明白为什么它不可迭代。有人可以帮我吗,我明天有截止日期:(.

Ps:这是我的代码 -->

<div class="col-8 col-md-10">
        <?PHP $id=get_post_field( 'post_author' )?>
        <h2><?PHP echo get_the_author_Meta('first_name',$id).' '.get_the_author_Meta('last_name',$id);?></h2>
        <p><?PHP echo get_the_author_Meta('user_description',$id) ?></p>
    </div>

这是错误 -->

    def regression_coefficients(x,y):
    """ This function calculates the regression offset(a) and the slope(b)
        X and Y are both list of integers or floatingpoints
    """
    Xi_keer_Yi = []
    Xi_kwadraat = [nummer ** 2 for nummer in x]
    
    for x,y in zip(x,y):
        Xi_keer_Yi.append(x * y)
        
    
    Xi_keer_Yi_som = sum(Xi_keer_Yi)
    Xi_kwadraat_som = sum(Xi_kwadraat)
    X_som = sum(x)
    Y_som = sum(y)
    
    if x < y:
        n = len(x)
    elif y < x:
        n = len(y)
    else:
        n = len(x)
        
    b_boven = n * Xi_keer_Yi_som - X_som * Y_som
    b_onder = n * Xi_kwadraat_som - (X_som)**2
    
    b = b_boven / b_onder
    
    a = y[0] - (b * x[0])
    
    
    
    return a,b
    
    
print(regression_coefficients([1,2,3],[2,1,3]))
#test functie
#Test.test_regressie.test(regression_coefficients)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)