决策树学习AllElectronics.py碰到的几个问题

报错:AttributeError: '_csv.reader' object has no attribute 'next'

原因:python版本问题

解决:将headers = reader.next()改为headers = next(reader)

报错:_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)

原因:csv文件并非二进制文件, 只是一个文本文件

解决:将allElectronicsData = open(r'F:/txt/AllElectronics.csv', 'rb')改成allElectronicsData = open(r'F:/txt/AllElectronics.csv', 'rt')

报错:ValueError: Expected 2D array, got 1D array instead

原因:数据维度不对,将其通过reshape进行转化

解决:将predictedY = clf.predict(newRowX)改成predictedY = clf.predict(newRowX.reshape(1,-1))

猜你喜欢

转载自blog.csdn.net/qq_20367813/article/details/82624167