Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 생성자
- arguments
- methodArea
- fuction
- eclipse
- run()
- Hashtable
- abstractclass
- ALTER
- string
- hashCode
- start()
- 추상클래스
- Eureka
- garbagecollection
- class
- super
- MSA
- 객체형변환
- hamobee
- 콘크리트클래스
- override
- constantnumber
- Vector
- value
- concreteclass
- Polymorphism
- reference
- object
- overload
Archives
- Today
- Total
뇌운동일지
[ R ] 빅데이터 수집 시스템 개발 본문
구글 뉴스 국내 사이트를 크롤링 하여 자연어 분석을 위해 txt 문서로 저장하고 워드클라우드 차트로 출력
1. 크롤링 툴 outwit-hub를 설치
기본설정과 기본위치에 설치
2. outwit-hub를 이용하여 크롤링 작업
( 주의점 : 저장시 엔코드 값 확인. 그리고 필요에 따라서 1차 전처리 가공을 수동 처리 해야함.
우리가 사용하는 자연어 처리 패키지가 5000 단어 미만만 가능하므로 주의 )
여기서 활용하기 어려운 데이터와 분량을 적절히 조정하고, 인코딩 방식을 바꾸어줌
수정 전과 후는 대략 이러한 차이가 있다.
3. R을 이용하여 자연어 분석을 해보자 (한글만 분석)
install.packages("multilinguer")
library(multilinguer)
install.packages(c('stringr', 'hash', 'tau', 'Sejong', 'RSQLite', 'devtools'), type = "binary")
install.packages("remotes")
remotes::install_github('haven-jeon/KoNLP', upgrade = "never", INSTALL_opts=c("--no-multiarch"))
library(KoNLP)
library(dplyr)
Sys.setenv(JAVA_HOME="C:/Java/jdk1.8.0_151")
useNIADic()
# txt 를 분석해보자
# 데이타 로드
txt <- readLines("./Data/googlenews2mod.txt")
head(txt)
# 이렇게 나와야 한다. 만약 인코딩이 적절하지 못할 경우,
# 이렇게 나오게 된다.
# 전처리
library(stringr)
# 정규식을 이요하여 문장속에 모든 특수 문자를 공백으로 대체한다.
txt <- str_replace_all(txt,"\\W"," ")
txt <- str_replace_all(txt, "[a-zA-z0-9]"," ")
# 명사 추출
nones <- extractNoun(txt)
# 단어별 빈도 분석을 해보자
wordcount <- table(unlist(nones))
# 데이타 프레임으로 전환
df_word <- as.data.frame(wordcount,stringsAsFactors = F)
head(df_word)
# 컬럼명을 쓰기 좋게 변경하자
df_word <- rename(df_word,word=Var1,freq=Freq)
# 글자의 길이가 두글자 이상만 추출하자 .
df_word <- filter(df_word, nchar(word) >= 2)
# 가장 빈도가 많은 단어 20개만 출력하시오 .
top20 <- df_word %>%
arrange(desc(freq)) %>%
head(20)
top20
4. 워드 클라우드 차트로 출력
# wordcloud 생성하기
# wordcloud 팩키지 설치
# 패키지 로드
library(wordcloud)
library(RColorBrewer)
# 색상표 생성
pal <- brewer.pal(8,"Dark2") # Dark2 색상목록에서 8개 생상 추출
set.seed(1234)
wordcloud(words=df_word$word,
freq = df_word$freq,
min.freq = 2,
max.words = 200,
random.order = F,
rot.per = 0.1,
scale = c(2,0.5),
colors = pal)
'R' 카테고리의 다른 글
[ R ] 빅데이터 분석 결과 시각화 (0) | 2020.08.03 |
---|---|
R 설치 및 셋팅 (0) | 2020.06.30 |
Comments