Let's make a positive / negative judgment tool into a band graph (Python)

It is always said that I will return to my parents' house. : man_tone3: Father "When are you getting married?" : woman_tone3: Mother "Not married yet?" : girl_tone3: Sister "When will you get married?" : baby_tone3: Niece "Won't you get married?" : baby_tone1: Niece 2 "Won't you get married?" : boy_tone3: My sister's husband "You should get married" : cat: "..."

: boy_tone5: Myself "Noisy! It's not that I'm bad that I can't get married, but the world is bad!"

Do you feel that the world is full of negative articles after marriage? I think there are many people who don't feel like getting married because of negative articles about marriage. Let's prove it with data!

Negative / positive judgment with Python

: point_down_tone1: That's why I made a positive / negative judgment tool by referring to the following code (Python) that makes a positive / negative judgment. https://news.mynavi.jp/article/zeropython-58/

: stopwatch :: desktop: rattling: stopwatch ::

: point_down_tone1: Chain. Yes, it's done. First, when I tried it with "Run, Melos!" Introduced in Mynavi News, the score was exactly the same. https://www.aozora.gr.jp/cards/000035/files/1567_14913.html Positive 0.29 0.20 {'p': 118,'n': 83,'e': 208}

With this condition, I would like to make a negative / positive judgment for articles about marriage. As for the dictionary used for judgment, the same as the article in Mynavi News, "Nouns of" Japanese Evaluation Polar Dictionary "of Tohoku University's Inui-Okazaki Laboratory" is used. .. .. But···· http://www.cl.ecei.tohoku.ac.jp/index.php?Open%20Resources%2FJapanese%20Sentiment%20Polarity%20Dictionary In this dictionary, "marriage" has a positive (p) setting and "divorce" has a negative (n) setting. Since this is not an evaluation for marriage, the following words (words including marriage) are ignored. Ceremonial occasion e ~ exists / enhances (existence / nature) Marriage p ~ (act) Marriage partner e ~ becomes / becomes (state) objective Wedding reception p ~ There is / enhances (existence / nature) Engagement p ~ (act) Go to honeymoon e ~ (place) Marriage of convenience n ~ (act) Divorce n ~ (act)

It's not sly ...?

Then, the articles are rated on a 5-point scale according to the score, and the results are listed. (Code below) The formula is " score "=" positive score "-" negative score " "Super positive (0.3 or more)" "Positive (0.1 or more)" "Neither (-0.1 or more)" "Negative (-0.3 or more)" "Super negative (less than -0.3)"

: point_down_tone1: The following is the part with the arrangement.

python


with open("list.txt", "a", encoding="utf8",  errors="replace") as file:
    if posi >= 0.3:
        judge = "Super positive"
    elif posi >= 0.1:
        judge = "positive"
    elif posi >= -0.1:
        judge = "Neither"
    elif posi >= -0.3:
        judge = "Negative"
    elif posi < -0.3:
        judge = "Super negative"
    else:
        judge = "Undecidable"
    print("Judgment", judge)
    file.write('{0}\t{1}\t{2}\t{3}\t{4:.2f}\t{5:.2f}\t{6}\n'.format(theme,title,judge,posi,res["p"] / cnt,res["n"] / cnt,res))
file.close()

Enter the search word in the argument theme and the title of the article in title.

First of all, I tried to judge the result of searching for "before marriage" ... https://wedding.mynavi.jp/contents/press/detail/post-63/ Positive 0.11801242236024845 0.23 0.11 {'p': 37,'n': 18,'e': 106} "Positive" judgment ... : boy_tone5: "Well, it's like this before marriage."

Next, I searched for "couple" and judged the URL that came out. https://wedding.mynavi.jp/contents/news/2016/09/ng1/ "Negative" judgment ... : boy_tone5: "Did you see it! I became negative as soon as I got married !!" (I'm happy for some reason)

For the time being, I tried 4 cases and got the following data. 20201213_cap.jpg How to read the text (tab delimited): Search word, article title, judgment result, score (positive-negative), positive (ratio), negative (ratio), all words

Let's graph this once. : part_alternation_mark: Create band graph in Python: part_alternation_mark:

Try to make data into a band graph with Python

It seems that few people create band graphs on the net, and I feel that the reference method is not so popular on the net. "List.txt" created above How to read the text (tab delimited): Search word, article title, judgment result, score (positive-negative), positive (ratio), negative (ratio), all words , Use only search word, judgment result.

python


import numpy as np
import matplotlib.pyplot as plt
jtypes=['Super positive','positive','Neither','Negative','超Negative']
color = ['#e41a1c','#ff7f00','#40cf40','#779ed8','#377eb8']
list_file = open('list.txt', 'r', encoding="utf-8")
data ={}
for line in list_file:
  channel,title,j_type,point,per1,per2,allword = line.split("\t")
  if channel not in data:
    data[channel]= np.zeros(len(jtypes)) 
  for kk in range(len(jtypes)):
    if j_type == jtypes[kk] :
      data[channel][kk] += 1
list_file.close()
values_arr=[]
tick_labels = []
np.array([])
for key,value in data.items():
  values_arr.append(value)
  tick_labels.append(key)
xx, yy = len(values_arr), len(jtypes)
data_arr = np.array(values_arr)

normalized = data_arr / data_arr.sum(axis=1, keepdims=True)
cumulative = np.zeros(xx)
tick = np.arange(xx,0,-1)
for y in range(yy):
    plt.barh(tick, normalized[:, y], left=cumulative, color=color[y], label=jtypes[y])
    cumulative += normalized[:, y]
plt.xlim((0, 1))
plt.yticks(tick, tick_labels, fontname="meiryo")
lg = plt.legend(bbox_to_anchor=(1.0, 1.0), loc='upper left', prop={"family":"meiryo"})
plt.title("Positive / negative judgment distribution", fontname="meiryo")
plt.show()

This is the graph obtained from the 4 data. test.png

Since the number of data is small, let's judge 10 articles for each search word. Also, try search results that appear in various words other than marriage. "Single" "Coronavirus" "After corona" "Monday" "Saturday" (10 articles for each word)

: stopwatch :: desktop: rattling: stopwatch ::

: point_down_tone1: Chain. Yes, it came out!

posinega.png 70% of "before marriage" and "after marriage" were "super positive" and "positive". Compared to other items, it is clear that there are many articles that are positive about "marriage." There are more positive articles than I thought "single"! (I'm happy for some reason)

Regarding "coronavirus", 60% were judged to be "super negative" or "negative", whereas It is interesting that there are few negative articles in "After Corona". It is interesting that "Saturday" is positive while "Monday" is relatively negative for many articles.

I found that there are few negative factors for "marriage" before and after marriage ...

"The world wasn't flooded with negative articles after marriage!" I'll look for another excuse orz

Among married and single people, it seems that married people are overwhelmingly happy. https://comemo.nikkei.com/n/nac91dd2ea623

: boy_tone5: By the way, I'm happy (not crying)

Recommended Posts

Let's make a positive / negative judgment tool into a band graph (Python)
Let's make a graph with python! !!
Let's make a GUI with python.
Let's make a shiritori game with Python
Let's make a voice slowly with Python
Let's make a web framework with Python! (1)
Let's make a combination calculation in Python
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Let's replace UWSC with Python (5) Let's make a Robot
Let's make a module for Python using SWIG
Try to make a command standby tool with python
[Let's play with Python] Make a household account book
Let's make a simple game with Python 3 and iPhone
[For play] Let's make Yubaba a LINE Bot (Python)
Make a CSV formatting tool with Python Pandas PyInstaller
[Super easy] Let's make a LINE BOT with Python.
Let's make a websocket client with Python. (Access token authentication)
Let's make a spot sale service 4 (in Python mini Hack-a-thon)
Let's make a Discord Bot.
Make a bookmarklet in Python
Make a fortune with Python
Let's make a rock-paper-scissors game
[5th] I tried to make a certain authenticator-like tool with python
[2nd] I tried to make a certain authenticator-like tool with python
How to make a string into an array or an array into a string in Python
Make multiple numerical elevation data into a single picture with Python
[3rd] I tried to make a certain authenticator-like tool with python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
Let's make a web chat using WebSocket with AWS serverless (Python)!
Let's make a remote rumba [Hardware]
Let's make a remote rumba [Software]
Let's make a spot sale service 2
Let's make a breakout with wxPython
python / Make a dict from a list.
Python: Negative / Positive Analysis: Text Analysis Application
Make a recommender system with python
[Python] Creating a scraping tool Memo
Let's make a supercomputer with xCAT
Make a nice graph with plotly
Let's make a spot sale service 3
[Ev3dev] Let's make a remote control program by Python with RPyC protocol
A note I looked up to make a command line tool in Python