# 글꼴 이름 찾기from matplotlib import font_manager
for font in font_manager.fontManager.ttflist:
if'Nanum'in font.name:
print(font.name, font.fname)
# 글꼴 설정import matplotlib.pyplot as plt
plt.rc('font', family='NanumGothic')
전처리 (지난 주와 같음)
!pip install kiwipiepy
import kiwipiepy
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
kiwi = kiwipiepy.Kiwi()
defextract_nouns(text):
for token in kiwi.tokenize(text):
if token.tag in {'NNG', 'NNP'}:
yield token.form
df = pd.read_excel('patents.xlsx')
cv = CountVectorizer(tokenizer=extract_nouns, min_df=10)
dtm = cv.fit_transform(df.abstract)
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
sim = cosine_similarity(doc_emb[[0]], doc_emb) # 문서 임베딩의 코사인 유사도
rank = np.argsort(sim[0]) # 유사도 순으로 정렬
rank = rank[::-1] # 내림차순으로 바꿈
df.iloc[rank].head() # 가장 비슷한 문서 5개
유사 난수 pseudorandom number
대부분의 컴퓨터는 결정론적(deterministic)으로 작동하여 난수(random number)를 생성할 수 없음
아주 긴 주기의 수열을 만들어 유사 난수로 사용
간단한 알고리즘: xn+1=(a⋅xn+c)(modm)
씨앗값으로부터 일정 항 이후부터 사용
보통 씨앗값은 현재 시각으로 결정
같은 결과를 재현하려고 할 때는 씨앗값을 고정하여 동일한 유사난수를 생성
스크리 플롯 scree plot
TruncatedSVD에서 "설명된 분산"의 시각화
PCA와 다르게 완전히 정렬되어 있지 않음
절벽 밑의 비탈(scree) 모양
import matplotlib.pyplot as plt
plt.plot(svd.explained_variance_)
for i, txt inenumerate(svd.explained_variance_):
plt.text(i, txt, str(i))