使用Ubuntu,我试图在这个片段中使用scikit-learn示例:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Examples of reading texts files and classifying them
"""
from __future__ import division
import datetime
import sklearn.datasets
time1 = datetime.datetime.now()
##from sklearn.datasets import fetch_20newsgroups
######## Reading text files
rootPath = r"/Home/web2py/corpus/20news-18828/"
但是,我收到了这个错误:
File "/usr/local/lib/python2.7/dist-packages/sklearn/datasets/base.py", line 201, in load_files
folders = [f for f in sorted(listdir(container_path))
OSError: [Errno 2] No such file or directory: '/Home/web2py/corpus/20news-18828/
我很喜欢Ubuntu和scikit-learn的东西。可能是什么问题/错误以及如何解决它??
答案 0 :(得分:0)
Thia为我工作:
rootPath =os.getenv('HOME/web2py/corpus/20news-18828')
但是,我收到了这个错误:
File "/home/mauricewaka/web2py/detscikit.py", line 19, in <module>
twenty_train = sklearn.datasets.load_files(rootPath,categories=categories, shuffle=True, random_state=42)
File "/usr/local/lib/python2.7/dist-packages/sklearn/datasets/base.py", line 201, in load_files
folders = [f for f in sorted(listdir(container_path))
TypeError: coercing to Unicode: need string or buffer, NoneType found
有关如何解决此错误的任何想法? 我尝试使用encoding ='utf-8',或删除编码参数但仍然得到相同的错误