text_plain_output_1.png
import csv

import gensim

import matplotlib.pyplot as plt

import numpy as np

with open('../input/tokenized-words-cord19-challenge/data.csv', newline='') as f:
    reader = csv.reader(f)
    data = list(reader)

model2 = gensim.models.Word2Vec(data, min_count=1, size=100, window=5, sg=1)

def truncate(n, decimals=0):
    multiplier = 10 ** decimals
    return int(n * multiplier) / multiplier
a = truncate(model2.similarity('risk', 'smoking'), 2)
b = truncate(model2.similarity('risk', 'heart'), 2)
c = truncate(model2.similarity('risk', 'pregnant'), 2)
d = truncate(model2.similarity('risk', 'cancer'), 2)
e = truncate(model2.similarity('risk', 'diabetes'), 2)
f = truncate(model2.similarity('risk', 'age'), 2)
g = truncate(model2.similarity('risk', 'asthma'), 2)
h = truncate(model2.similarity('risk', 'HIV'), 2)
i = truncate(model2.similarity('risk', 'transplant'), 2)
j = truncate(model2.similarity('risk', 'obesity'), 2)
k = truncate(model2.similarity('risk', 'immunocompromised'), 2)
l = truncate(model2.similarity('risk', 'underweight'), 2)
m = truncate(model2.similarity('risk', 'liver'), 2)
n = truncate(model2.similarity('risk', 'bronchitis'), 2)
o = truncate(model2.similarity('risk', 'COPD'), 2)

objects = ('Smoking', 'Heart Disease', 'Pregnancy', 'Cancer', 'Diabetes', 'Age', 'Asthma', 'HIV', 'Transplant', 'Obesity', 'Immunocompromised', 'Underweight', 'Liver Disease', 'Chronic Bronchitis', 'COPD')
y_pos = np.arange(len(objects))
similarity = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o]
fig = plt.figure(1, [15, 10])
axes = plt.gca()
axes.set_ylim([0, 1])
plt.bar(y_pos, similarity, align='center', alpha=0.5)
plt.xticks(y_pos, objects, rotation=90)
plt.ylabel('Cosine similarity with the word "risk" using Skip Gram model')
plt.title('Risk Factors')
count = -0.27
for i in similarity:
    plt.text(count, i - 0.05, str(i))
    count += 1
plt.show()