【问题标题】:fastText python implementation creating training and testing setfastText python 实现创建训练和测试集
【发布时间】:2017-09-11 18:20:32
【问题描述】:

我正在网页抓取,我将我的 utf-8 保存到 csv,清理它,现在我正在尝试创建我的训练和测试文件以便能够使用 Facebook 的 fastText,现在这就是我所拥有的,它正在提供我错了

from sklearn.cross_validation import train_test_split

y_all = df["normalized"]
X_all = df.drop('normalized', axis = 1)

X_train, X_test, y_train, y_test = train_test_split(X_all, y_all, `test_size=0.3, random_state=1)`
import fasttext as ft
classifier = ft.supervised(X_train, y_train)

这是它返回的错误,这是 jupyter notebook 中 windows 的 fastText

TypeError                                 Traceback (most recent call last)
<ipython-input-47-1f4fa41d367f> in <module>()
----> 1 classifier = ft.supervised(X_train, y_train)

fasttext/fasttext.pyx in fasttext.fasttext.supervised (fasttext/fasttext.cpp:6665)()

fasttext/fasttext.pyx in fasttext.fasttext.train_wrapper (fasttext/fasttext.cpp:4732)()

C:\Program Files\Anaconda3\lib\genericpath.py in isfile(path)
     28     """Test whether a path is a regular file"""
     29     try:
---> 30         st = os.stat(path)
     31     except OSError:
     32         return False

TypeError: argument should be string, bytes or integer, not DataFrame

【问题讨论】:

  • 试试y_all = df["normalized"].valuesX_all = df.drop('normalized', axis = 1).values

标签: python pandas machine-learning nlp fasttext


【解决方案1】:

@kwashington122 我认为您使用受监督的方式是错误的。 fasttext.supervised 是一个分类器,它将包含标记数据的训练文件作为输入,例如 X_train:

text1 标签_x
text2 label_y

您需要指定标签前缀,以便 fasttext 可以捕获您拥有的不同标签。 model = fasttext.supervised(X_train,'model', label_prefix='label_') fasttext 将在我的示例 x 和 y 中检测到 2 个标签(因为我指定 label_ 作为标签的前缀)。

然后,为了在一组新数据上预测或测试分类器,您只需执行以下操作: model.test(X_test) 或者,如果您想预测文本或句子的标签,请执行以下操作:

model.predict(X_test) ## where text has no labels.

我的回答有点晚了抱歉刚刚在寻找我的问题的答案时打了这个问题。

【讨论】:

    猜你喜欢
    • 2020-07-07
    • 2015-07-16
    • 2019-12-03
    • 1970-01-01
    • 2019-04-20
    • 2017-11-01
    • 1970-01-01
    • 2015-03-29
    • 2015-01-17
    相关资源
    最近更新 更多