Python-이론/python-인공지능
machine Learning결과로 그래프 만들기
sang_hoony
2018. 4. 22. 14:41
machine Learning결과로 그래프 만들기
이번엔 앞서 무슨나라언어 인지 판단했던 결과를 통해서 그래프를 그려 보겠습니다.
import matplotlib.pyplot as plt import pandas as pd import json #그래프를 만들기 전에 2차원 배열로 만들어주기 with open ('./lang/freq.json','r',encoding = 'utf-8') as fp: freq = json.load(fp) langdic = {} for idx, label in enumerate(freq[0]['labels']): data = freq[0]['freqs'][idx] if not (label in langdic): langdic[label] = data continue for i, v in enumerate(data): langdic[label][i] = (langdic[label][idx]+v)/2 asciList = [chr(n) for n in range(97,97+26)] pdr = pd.DataFrame(langdic, index = asciList) plt.style.use('ggplot') pdr.plot(kind = 'bar',subplots = True , ylim=(0,0.15)) plt.savefig('lang-plot3.png')
코드를 실행시키기 전 export MPLBACKEND = "agg"를 먼저 실행 후 실행시켜주자