當前位置:首頁 » 分析預測 » python股票評論情感分析
擴展閱讀
央視財經股票大數據平台 2024-09-24 21:28:46
股票基金幾年分紅 2024-09-24 20:55:18

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相對來說是一種比較高端的學科,需要有很強的邏輯能力。所以入門是非常困難的,如果真的要學習,是需要很大的毅力去堅持下去的,而且不短時間就能入門了,要有所心理准備。