[AttributeError:' tuple'对象没有属性' lower']

时间:2018-04-10 21:16:24

标签: python python-3.x

class Presenter
{
    public ObservableCollection<TVM> ItemsVM {get;}
        = new ObservableCollection<TVM>();

    public Loader _loader 
    = new Loader(some_well_known_directory_path);

    void Populate()
    {
        foreach (T t_item in _loader.GetItems())
        {
            ItemsVM.Add(new TVM(t_item));
        }
    }
}

class Loader
{
    readonly string _path;

    public Loader(string path)
    {
        _path = path;
    }

    public IEnumerable<T> GetItems()
    {
        var result_list = new List<T>();

        Parallel.ForEach(Directory.GetFiles(_path), fname =>
        {
            try
            {
                result_list.Add(T.Load(fname));
            }
            catch (Exception e)
            {
                logger.Warn(e.Message);
            }
        });

        return result_list;
    }
}

这是我的训练数据,我使用的是CountVectorizer,但它显示错误

train = [('I love this sandwich.','pos'),
     ('This is an amazing place!', 'pos'),
     ('I feel very good about these beers.', 'pos'),
     ('This is my best work.', 'pos'),
     ('What an awesome view', 'pos'),
     ('I do not like this restaurant', 'neg'),
     ('I am tired of this stuff.', 'neg'),
     ("I can't deal with this.", 'neg'),
     ('He is my sworn enemy!.', 'neg'),
     ('My boss is horrible.', 'neg')
    ]

请帮助我。

1 个答案:

答案 0 :(得分:0)

您错误地使用了cv.fit_transform方法。根据文档,此方法接受可迭代的字符串。您正在为方法提供元组列表。

以下摘自documentation

  

fit_transform raw_documents,y =无)   参数:raw_documents :iterable

     

一个可生成str,unicode或文件对象的iterable。

一种方法可以做到这一点:

text_train_cv = cv.fit_transform(list(zip(*train))[0])