CNN应用:文本情感预测

数据示例如下所示,

UserName,ScreenName,Location,TweetAt,OriginalTweet,Sentiment

3799,48751,London,16-03-2020,@MeNyrbie @Phil_Gahan @Chrisitv https://t.co/iFz9FAn2Pa and https://t.co/xX6ghGFzCC and https://t.co/I2NlzdxNo8,Neutral

3800,48752,UK,16-03-2020,advice Talk to your neighbours family to exchange phone numbers create contact list with phone numbers of neighbours schools employer chemist GP set up online shopping accounts if poss adequate supplies of regular meds but not over order,Positive

3801,48753,Vagabonds,16-03-2020,"Coronavirus Australia: Woolworths to give elderly, disabled dedicated shopping hours amid COVID-19 outbreak https://t.co/bInCA9Vp8P",Positive

3802,48754,,16-03-2020,"My food stock is not the only one which is empty...

... ... 

数据读取如下所示,

train_path = r'./train.csv'
test_path = r'./test.csv'

test_data = pd.read_csv(test_path)
test_data = test_data.OriginalTweet

# 读取训练集数据

# 将情绪标签转化为数值标签
def label_numeric_transfer(labels):
    label_names = ['Neutral', 'Positive', 'Negative', 'Extremely Positive',  'Extremely Negative']

    numeric_labels = []
    for label in labels:
        if label not in label_names:
            print('WARNING! Invalid label named {}'.format(label))
        if label == label_names[0]:
            numeric_labels.append(0)
        elif label == label_names[1]:
            numeric_labels.append(1)
        elif label == label_names[2]:
            numeric_labels.append(2)
        elif label == label_names[3]:
            numeric_labels.append(3)
        elif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值