[Python]错误集合
#1 ValueError: matrices are not aligned
解答参见https://developer.aliyun.com/ask/275414
#2 ValueError: Unable to coerce to Series, length must be 3: given 10
解答:出自10*2的矩阵乘以2*1的矩阵
data.iloc[:, i] = data.iloc[:, parentIdx] * weight + noise * noiseRatio
如果该形式放到matlab中矩阵乘法就没问题了,但在python中报错了
此处的3是data.iloc[:,parentIdx] * weight得到10行3列的矩阵,10是指10行
改成data.iloc[:,parentIdx].dot(weight)就不出现该问题了
但是加上noise * noiseRatio仍然报错ValueError: Unable to coerce to Series, length must be 1: given 10
经分析,加号前半部分是pandas dataframe数据结构,加号后面noise是numpy数据结构
所以进行统一数据结构就不报错了,noise = pd.DataFrame(noise)
#3 ValueError: ndarray is not contiguous
更改前:#temp_x = mat(dataset.iloc[:, x]).reshape(l, 1)
更改后:temp_x = mat(dataset.iloc[:, x].values).reshape(l, 1)
参见:https://cloud.tencent.com/developer/ask/sof/105769773
#4 TypeError: unsupported format string passed to tuple.__format__
更改前:print(f'F1:{single_process():.3f}')
是只导出一个参数值,想修改后导出4个参数值,报错;修改后,新错误TypeError: not all arguments converted during string formatting
更改后:print('Accu:%.3f, Recall:%.3f, Precision:%.3f, F1:%.3f'%(single_process()))
参考:https://wenku.csdn.net/answer/a1db8ebce02e4509bf8efdff76ed62a0
https://blog.csdn.net/lvsehaiyang1993/article/details/80909984
#5 ModuleNotFoundError: No module named 'src.partion'
将src文件夹下的partion复制出来到与main函数同层文件夹
参考:https://stackoverflow.com/questions/57078689/module-not-found-error-no-module-named-src