gpt4 book ai didi

python - sklearn : shapes not aligned 中的值错误

转载 作者:行者123 更新时间:2023-12-01 07:03:48 25 4
gpt4 key购买 nike

我试图返回我通过程序运行的测试分数,但无论我尝试什么,我都会收到错误:

ValueError                                Traceback (most recent call last)
<ipython-input-19-4b49cb58c813> in <module>()
----> 1 print(model_final.score(X_train, y_train))
2 print(model_final.score(X_test, y_test))

3 frames
/usr/local/lib/python3.6/dist-packages/sklearn/utils/extmath.py in safe_sparse_dot(a, b, dense_output)
140 return ret
141 else:
--> 142 return np.dot(a, b)
143
144

ValueError: shapes (353,10) and (172,) not aligned: 10 (dim 1) != 172 (dim 0)

完整代码可见here .

最佳答案

问题就在眼前

model_final = model

此语句不会创建模型的副本,它只是执行shallow copy因此,当您更改 model 时,甚至 model_final 也会发生变化。为了避免这种情况,您需要进行deepcopy as

from copy import deepcopy
model_final = deepcopy(model)

这将执行深层复制,并且您对model所做的任何更改都不会影响model_final

关于python - sklearn : shapes not aligned 中的值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58524955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com