在Python中使用for循环创建数组

2024-04-27 00:42:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个数组:

  • 所有的预言都是(1200,6565)

  • 预测是(6565,)

predictions_all中,我拥有随机林中每棵树的所有预测,在predictions中,每个预测的聚合平均值(即predictions_all中第一列的平均值是predictions中的第一个值)。你知道吗

这是我的密码:

from sklearn.metrics import mean_squared_error

MSE_i_1 = []
for i in range(len(predictions_all)):
    x = mean_squared_error([predictions_all[i,0]],[predictions[0]])
    MSE_i_1.append(x)
MSE_i_1 = np.asarray(MSE_i_1)

MSE_i_1(1200,)数组。有所有的MSE为每个树在所有。你知道吗

问题是我只对第一列做了,我想对所有6565列进行迭代。因此,我希望有一个(1200,6565)的数组,但我不知道如何循环每个列以及如何确保我有一个(1200,6565)数组而不是一个列表。你知道吗


Tags: infromimport密码forerror数组sklearn