如何以更好的优化方式计算 cross_val_score() 的平均值?

问题描述

为了训练,我使用了一个包含 13 个特征和 304 行的样本数据。我正在尝试评估我使用的 RandomForestClassifier() 的分数。为了使分数预测更精确,我将 cross_val_score() 的所有结果添加一个列表中,并获得该列表中数字的平均值。我还使用计时器来查看运行它需要多长时间。 这是代码的 cross_val_score() 部分:

Traceback (most recent call last):
  File "c:\Users\Desktop\working_dir\test.py",line 26,in <module>
    read.appendChild(xml)
  File "C:\Users\AppData\Local\Programs\Python\python39\lib\xml\dom\minidom.py",line 115,in appendChild
    if node.nodeType == self.DOCUMENT_FRAGMENT_NODE:
AttributeError: 'str' object has no attribute 'nodeType'

这是我得到的:

start = time.time()
big_mean = list()
i = 0
while i < 100:
    score = np.mean(cross_val_score(RFC,X,y,cv=5))
    big_mean.append(score)
    i += 1
print(sum(big_mean)/len(big_mean))
end = time.time()
print("Timer: ",end - start)

我觉得代码优化得很差。如果有更多数据,它甚至会花费超过 75 秒。哪些更改会使其成为更好的优化代码

解决方法

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

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

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