报错笔记
- 1. 使用pydub时报错
- 2. 使用sklearn的joblib库报错
- 3. 使用pandas读取csv时报错ParserError:Error tokenizing data.C error:Expected 2 fields in line 407,saw 3.
- 4. 访问dataframe报错'DataFrame' object is not callable
- 5. 对模型打分报错Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].
- 6. read_csv报错
- 7. resample报错 Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
- 8. 执行dataframe的append方法报错AttributeError: 'DataFrame' object has no attribute 'append'
- 9. 实例化SelectKBest时卡方检验报错 name 'chi2' is not defined
- 10. 模型fit时报错 Unknown label type: 'continuous'
- 11.过采样设定ration报错 __init__() got an unexpected keyword argument 'ratio'
- 12. 使用DataLoader导入数据时报错ValueError: num_samples should be a positive integer value, but got num_samples=0
1. 使用pydub时报错
RuntimeWarning: Couldn't find ffplay or avplay - defaulting to ffplay, but may not work
warn("Couldn't find ffplay or avplay - defaulting to ffplay, but may not work", RuntimeWarning)
[Errno 13] Permission denied: 'C:\\Users\\MyPC\\AppData\\Local\\Temp\\tmpkb_z2s33.wav'
解决
windows上需要安装ffmpeg,要先下载https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-2023-05-04-git-4006c71d19-full_build.7z解压,将目录中的bin文件夹路径加入系统环境变量
2. 使用sklearn的joblib库报错
from sklearn.externals import joblib
cannot import name 'joblib' from 'sklearn.externals'
解决
安装conda install joblib
import joblib
3. 使用pandas读取csv时报错ParserError:Error tokenizing data.C error:Expected 2 fields in line 407,saw 3.
ParserError:Error tokenizing data.C error:Expected 2 fields in line 407,saw 3.
解决
加入参数error_bad_lines=False
pandas.read_csv(filePath,error_bad_lines=False)
4. 访问dataframe报错’DataFrame’ object is not callable
ctype("Date")
'DataFrame' object is not callable
解决
应该使用ctype[“Date”]
5. 对模型打分报错Target is multiclass but average=‘binary’. Please choose another average setting, one of [None, ‘micro’, ‘macro’, ‘weighted’].
Target is multiclass but average='binary'. Please choose another average setting, one of [None, 'micro', 'macro', 'weighted'].
解决
需要增加average参数
f1_score(y_test, y_predict, average='micro')
precision_score(y_test, y_predict, average='weighted')
6. read_csv报错
6.1
MemoryError: Unable to allocate 128. KiB for an array with shape (16384,) and data type float64
Error tokenizing data. C error: out of memory
解决
关掉不用的notebook,一般是内存不够了
6.2
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xcc in position 0: invalid continuation byte
解决
encoding中更换各种编码:gbk2132 gbk gb18030
6.3
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
解决
有可能是的文件路径没有,如果是windows,需要加双斜杠
df=pd.read_csv("C:\\Users\\xxxx\\Downloads\30.csv",encoding="gbk")```
7. resample报错 Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘Index’
df.index=pd.to_datetime(df.index)
或者
df["date"] = pd.to_datetime(df["时间列"])
df=df.set_index(df["date"])
8. 执行dataframe的append方法报错AttributeError: ‘DataFrame’ object has no attribute ‘append’
AttributeError: 'DataFrame' object has no attribute 'append'
解决
使用pd的concat
df=pd.concat([df,c],ignore_index=True)
9. 实例化SelectKBest时卡方检验报错 name ‘chi2’ is not defined
name 'chi2' is not defined
解决
chi2也需要导入包:from sklearn.feature_selection import SelectKBest,chi2
10. 模型fit时报错 Unknown label type: ‘continuous’
解决方法:y=y.astype(str)或者y=y.astype(int)
11.过采样设定ration报错 init() got an unexpected keyword argument ‘ratio’
解决方法:sampling_strategy代替ration
12. 使用DataLoader导入数据时报错ValueError: num_samples should be a positive integer value, but got num_samples=0
解决方法:shuffle=False