当前位置:首页 » 分析预测 » python股票评论情感分析
扩展阅读
股票基金几年分红 2024-09-24 20:55:18
证券开户股票交易费 2024-09-24 20:54:40

python股票评论情感分析

发布时间: 2021-06-05 07:05:31

1. 用python做情感分析是text processing是自己搜集的数据吗

提供了一组操作协议接口,主要用于规定采用哪种协议进行数据的读写,它内部包含一个传输类(TTransport)成员对象,通过TTransport对象从输入输出流中读写数据;
它规定了很多读写方式,例如:
readByte()
readDouble()
readString()

2. 用python找文献,并从文本中分析情绪,做一个数据分析

到你的系统“终端”(macOS, Linux)或者“命令提示符”(Windows)下,进入我们的工作目录demo,执行以下命令。
pip install snownlppip install -U textblobpython -m textblob.download_corpora

好了,至此你的情感分析运行环境已经配置完毕。
在终端或者命令提示符下键入:
jupyter notebook

你会看到目录里之前的那些文件,忽略他们就好。

3. 如何用Python做情感分析

什么是python ??

4. 给了一堆数据 用python做文本情感分析 但是课题要求是事先将无意义的评论去处 这要怎么做

既然你已经学到了数据分析,那么基本的语法应该大都知道了吧。
这无非就是筛选数据的问题,先搞清楚什么是“无意义的评论”,它满足什么条件,再遍历评论,如果满足这个“无意义”的条件,那么就删除掉就是了。

5. 用python对中文做情感分析,有没有好的接口推荐

import jieba
import numpy as np

# 打开词典文件,返回列表
def open_dict(Dict='hahah',path = r'/Users/zhangzhenghai/Downloads/Textming/'):
path = path + '%s.txt' %Dict
dictionary = open(path, 'r', encoding='utf-8')
dict = []
for word in dictionary:
word = word.strip('\n')
dict.append(word)
return dict

def judgeodd(num):
if num % 2 == 0:
return 'even'
else:
return 'odd'

deny_word = open_dict(Dict='否定词')
posdict = open_dict(Dict='positive')
negdict = open_dict(Dict = 'negative')

degree_word = open_dict(Dict = '程度级别词语',path=r'/Users/zhangzhenghai/Downloads/Textming/')
mostdict = degree_word[degree_word.index('extreme')+1: degree_word.index('very')] #权重4,即在情感前乘以3
verydict = degree_word[degree_word.index('very')+1: degree_word.index('more')] #权重3
moredict = degree_word[degree_word.index('more')+1: degree_word.index('ish')]#权重2
ishdict = degree_word[degree_word.index('ish')+1: degree_word.index('last')]#权重0.5

def sentiment_score_list(dataset):
seg_sentence = dataset.split('。')

count1 = []
count2 = []
for sen in seg_sentence: # 循环遍历每一个评论
segtmp = jieba.lcut(sen, cut_all=False) # 把句子进行分词,以列表的形式返回
i = 0 #记录扫描到的词的位置
a = 0 #记录情感词的位置
poscount = 0 # 积极词的第一次分值
poscount2 = 0 # 积极反转后的分值
poscount3 = 0 # 积极词的最后分值(包括叹号的分值)
negcount = 0
negcount2 = 0
negcount3 = 0
for word in segtmp:
if word in posdict: # 判断词语是否是情感词
poscount +=1
c = 0
for w in segtmp[a:i]: # 扫描情感词前的程度词
if w in mostdict:
poscount *= 4.0
elif w in verydict:
poscount *= 3.0
elif w in moredict:
poscount *= 2.0
elif w in ishdict:
poscount *= 0.5
elif w in deny_word: c+= 1
if judgeodd(c) == 'odd': # 扫描情感词前的否定词数
poscount *= -1.0
poscount2 += poscount
poscount = 0
poscount3 = poscount + poscount2 + poscount3
poscount2 = 0
else:
poscount3 = poscount + poscount2 + poscount3
poscount = 0
a = i+1
elif word in negdict: # 消极情感的分析,与上面一致
negcount += 1
d = 0
for w in segtmp[a:i]:
if w in mostdict:
negcount *= 4.0
elif w in verydict:
negcount *= 3.0
elif w in moredict:
negcount *= 2.0
elif w in ishdict:
negcount *= 0.5
elif w in degree_word:
d += 1
if judgeodd(d) == 'odd':
negcount *= -1.0
negcount2 += negcount
negcount = 0
negcount3 = negcount + negcount2 + negcount3
negcount2 = 0
else:
negcount3 = negcount + negcount2 + negcount3
negcount = 0
a = i + 1
elif word == '!' or word == '!': # 判断句子是否有感叹号
for w2 in segtmp[::-1]: # 扫描感叹号前的情感词,发现后权值+2,然后退出循环
if w2 in posdict or negdict:
poscount3 += 2
negcount3 += 2
break
i += 1

# 以下是防止出现负数的情况
pos_count = 0
neg_count = 0
if poscount3 <0 and negcount3 > 0:
neg_count += negcount3 - poscount3
pos_count = 0
elif negcount3 <0 and poscount3 > 0:
pos_count = poscount3 - negcount3
neg_count = 0
elif poscount3 <0 and negcount3 < 0:
neg_count = -pos_count
pos_count = -neg_count
else:
pos_count = poscount3
neg_count = negcount3
count1.append([pos_count,neg_count])
count2.append(count1)
count1=[]

return count2

def sentiment_score(senti_score_list):
score = []
for review in senti_score_list:
score_array = np.array(review)
Pos = np.sum(score_array[:,0])
Neg = np.sum(score_array[:,1])
AvgPos = np.mean(score_array[:,0])
AvgPos = float('%.lf' % AvgPos)
AvgNeg = np.mean(score_array[:, 1])
AvgNeg = float('%.1f' % AvgNeg)
StdPos = np.std(score_array[:, 0])
StdPos = float('%.1f' % StdPos)
StdNeg = np.std(score_array[:, 1])
StdNeg = float('%.1f' % StdNeg)
score.append([Pos,Neg,AvgPos,AvgNeg,StdPos,StdNeg])
return score

data = '用了几天又来评价的,手机一点也不卡,玩荣耀的什么的不是问题,充电快,电池够大,玩游戏可以玩几个小时,待机应该可以两三天吧,很赞'
data2 = '不知道怎么讲,真心不怎么喜欢,通话时声音小,新手机来电话竟然卡住了接不了,原本打算退,刚刚手机摔了,又退不了,感觉不会再爱,像素不知道是我不懂还是怎么滴 感觉还没z11mini好,哎要我怎么评价 要我如何喜欢努比亚 太失望了'

print(sentiment_score(sentiment_score_list(data)))
print(sentiment_score(sentiment_score_list(data2)))

6. 怎样用python处理文本情感分析

Python 有良好的程序包可以进行情感分类,那就是Python 自然语言处理包,Natural Language Toolkit ,简称NLTK 。NLTK 当然不只是处理情感分析,NLTK 有着整套自然语言处理的工具,从分词到实体识别,从情感分类到句法分析,完整而丰富,功能强大。

7. 有大神会用python做网络评论文本的情感分析么有偿

这个自学一会就会了,给你一个模型,自己研究一下,没那么难。

importjieba
importnltk.classify.util
fromnltk.
fromnltk.corpusimportnames

defword_feats(words):
returndict([(word,True)forwordinwords])

text1=open(r"积极.txt","r").read()
seg_list=jieba.cut(text1)
result1="".join(seg_list)

text2=open(r"消极.txt","r").read()
seg_list=jieba.cut(text2)
result2="".join(seg_list)


#数据准备
positive_vocab=result1
negative_vocab=result2
#特征提取
positive_features=[(word_feats(pos),'pos')forposinpositive_vocab]
negative_features=[(word_feats(neg),'neg')forneginnegative_vocab]
train_set=negative_features+positive_features
#训练模型
classifier=NaiveBayesClassifier.train(train_set)

#实战测试
neg=0
pos=0
sentence=input("请输入一句你喜欢的话:")
sentence=sentence.lower()
seg_list=jieba.cut(sentence)
result1="".join(seg_list)
words=result1.split("")

forwordinwords:
classResult=classifier.classify(word_feats(word))
ifclassResult=='neg':
neg=neg+1
ifclassResult=='pos':
pos=pos+1

print('积极:'+str(float(pos)/len(words)))
print('消极:'+str(float(neg)/len(words)))

8. python爬虫获取东方财富股票论坛内容分析,怎样

付费可以帮写

9. 用Python 进行股票分析 有什么好的入门书籍或者课程吗

概率炒股法:
用python获取股票价格,如tushare,如果发现股票当天涨幅在大盘之上(2点30到2点50判断),买入持有一天,下跌当天就别买,你可以用概率论方法,根据资金同时持有5支,10支或20支,这样不怕停盘影响,理论上可以跑赢大盘。
还有一种是操作etf,如大盘50 etf,300 etf,中小板etf,创业板etf,当天2.30分判断那个etf上涨就买入那支,不上涨什么都不买,持有一天,第二天如是。

10. 用Python 进行股票分析 有什么好的入门书籍或者课程吗

个人觉得这问题问的不太对,说句不好的话,你是来搞编程的还是做股票的。


当然,如果题主只是用来搜集资料,看数据的话那还是可以操作一波的,至于python要怎么入门,个人下面会推荐一些入门级的书籍,通过这些书籍,相信楼主今后会有一个清晰的了解(我们以一个完全不会编程的的新手来看待)。

《Learn Python The Hard Way》,也就是我们所说的笨办法学python,这绝对是新手入门的第一选择,里面话题简练,是一本以练习为导向的教材。有浅入深,而且易懂。

其它的像什么,《Python源码剖析》,《集体智慧编程》,《Python核心编程(第二版)》等题主都可以适当的选择参读下,相信都会对题主有所帮助。

最后,还是要重复上面的话题,炒股不是工程学科,它有太多的变数,对于现在的智能编程来说,它还没有办法及时的反映那些变数,所以,只能当做一种参考,千万不可过渡依赖。


结语:pyhton相对来说是一种比较高端的学科,需要有很强的逻辑能力。所以入门是非常困难的,如果真的要学习,是需要很大的毅力去坚持下去的,而且不短时间就能入门了,要有所心理准备。