如何解决为什么我在 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 举报,一经查实,本站将立刻删除。