神经网络基础
学习链接:https://www.cnblogs.com/pinard/category/894694.html
FastText模型进行文本分类
#coding = utf-8
#Author:Shanv
#function:
import pandas as pd
import numpy as np
import datetime
import codecs
import jieba
import fastText
from prettytable import PrettyTable
#数据读取
def load_data(filePath):
#读取文件
f = codecs.open(filePath, 'r', encoding='utf-8')
labels = []
contents = []
for line in f.readlines():
try:
label, content = line.strip().split('\t')
if content:
labels.append(label)
contents.append(content)
except:
pass
df = pd.DataFrame({'title':labels,'content':contents})
return df
def cut_word(content):
"""结巴分词
:param content: 分词文本
:return: word:分好后的单词数据集(Series类型)
"""
word = content.map(lambda x: [w for w in list(jieba.cut(x)) if len(w) != 1])
return word
def make_fasttext_data(data_cuted, outFile, train=True, label=None):
"""把分好词后的数据转换成