将您自己的文本数据集加载到 scikit-learn [英] Loading your own text dataset to scikit-learn

查看:43
本文介绍了将您自己的文本数据集加载到 scikit-learn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过加载我自己的数据集来尝试一些算法.我对加载文本文件特别感兴趣(非常类似于 20 NewsGroups 数据集 http://scikit-learn.org/stable/datasets/index.html#general-dataset-api).是否有任何文档解释加载样本数据集以外的数据的格式(和程序)?

I want to try out a few algorithms in by loading my own dataset. I'm specifically interested in loading text files (very similar to the 20 NewsGroups dataset http://scikit-learn.org/stable/datasets/index.html#general-dataset-api). Is there any documentation that explains the format (and the procedure) for loading in data other than the sample datasets?

谢谢.

推荐答案

TfidfVectorizer 和 scikit-learn 中的其他文本向量化器类只将 Python unicode 字符串列表作为输入.因此,您可以根据来源以您想要的方式加载文本:使用 SQLAlchemy 的数据库查询、来自 HTTP API 的 json 流、CSV 文件或文件夹中的随机文本文件.

TfidfVectorizer and others text vectorizers classes in scikit-learn just take a list of Python unicode strings as input. You can thus load the text the way you want depending on the source: database query using SQLAlchemy, json stream from an HTTP API, a CSV file or random text files in folders.

对于最后一个选项,如果类信息存储在包含文本文件的文件夹名称中,您可以使用 load_files 实用功能.

For the last option, if the class information is stored in the folder names holding the text files you can use the load_files utility function.

这篇关于将您自己的文本数据集加载到 scikit-learn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆