BABIP
์ฌ์ด ๋จธ์ ๋ฌ๋ ๋ชจ๋ธ ๊ฐ์ ์ ์ํ ํ์ด์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
Features
- ๊ฐ๋ฐ ์๋: ์ธ๊ณต ์ง๋ฅ ๋ถ์ผ์ ๋์ ์ง์ ์ฅ๋ฒฝ์ ์์ ๊ณ ์ ๊ฐ๋ฐ
- ํ๊ตญ์ด ๋ฐ์ดํฐ ์ต์ ํ: ํ๊ตญ์ด ๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ์ ์ด๋ ค์์ ๊ฒช์ง ์๋๋ก ํ๊ตญ์ด ๋ฐ์ดํฐ์ ์ต์ ํ
- ์ฌ์ด ์ฌ์ฉ: ๋ชจ๋ ๊ธฐ๋ฅ์ ์ฝ๋ ํ ์ค๋ก ๊ตฌํ ๊ฐ๋ฅ
Installation
Dependencies
BABIP requires:
- scikit-learn
User Installation
pip install BABIP
Modules
rec
์ถ์ฒ ์์คํ ๊ฐ๋ฐ์ ์ํ ๋ชจ๋
- tfidf(): TF-IDF ํ๋ ฌ
rec.tfidf(data, col_contents)
- cos_similarity(): ์ฝ์ฌ์ธ ์ ์ฌ๋
rec.cos_similarity(data, col_contents)
- recommend(): ์ถ์ฒ ์์คํ
rec.recommend(title, data, col_title, col_contents)
์์ ๋ฐ์ดํฐ (movie_data.csv)
title | story |
---|---|
ํด๋์ | ๊ฐ์ ๋ํ์ ๋ค๋๋ ์งํ(์์์ง ๋ถ)์ ์๊ฒฝ(์ด์์ธ ๋ถ)์ ์ฐ๊ทน๋ฐ ์ ๋ฐฐ ์๋ฏผ(์กฐ์ธ์ฑ ๋ถ)์ ์ข์ํ๋ค. ํ์ง๋ง... |
์ธํฐ์คํ ๋ผ | ์ธ๊ณ ๊ฐ๊ตญ์ ์ ๋ถ์ ๊ฒฝ์ ๊ฐ ์์ ํ ๋ถ๊ดด๋ ๋ฏธ๋๊ฐ ๋ค๊ฐ์จ๋ค. ์ง๋ 20์ธ๊ธฐ์ ๋ฒํ ์๋ชป์ด ์ ์ธ๊ณ์ ์ธ ์๋ ๋ถ์กฑ์ ๋ถ๋ฌ์๊ณ , NASA๋ ํด์ฒด๋์๋ค. ์ด๋... |
์ธ์ ์ | ๋๋ฆผ๋จธ์ ์ด๋ผ๋ ๊ธฐ๊ณ๋ก ํ์ธ์ ๊ฟ๊ณผ ์ ์ํด ์๊ฐ์ ๋นผ๋ผ ์ ์๋ ๋ฏธ๋์ฌํ.โ๋ ์ฝ๋ธโ(๋ ์ค๋๋ฅด๋ ๋์นดํ๋ฆฌ์ค)๋ ์๊ฐ์ ์งํค๋ ํน์๋ณด์์์์ด๋ฉด์ ๋ํ ์ต๊ณ ์ ์ค๋ ฅ์ผ๋ก ์๊ฐ์ ํ์น๋ ๋๋์ด๋ค... |
์์ ์ฝ๋
from babip import rec
import pandas as pd
# ๋ฐ์ดํฐ ๋ก๋
data_path = './../movie_data.csv'
data = pd.read_csv(data_path, encoding='cp949')
# ์นผ๋ผ ์ด๋ฆ
col_title = 'title' # ์์ดํ
์ด๋ฆ ์ ๋ณด๋ฅผ ๋ด๋ ์นผ๋ผ์ ์ด๋ฆ
col_contents = 'story' # ๋ฌธ์ ์ ์ฌ๋ ๋น๊ต์ ์ฐ์ผ ์์ฐ์ด ์ ๋ณด๋ฅผ ๋ด๋ ์นผ๋ผ์ ์ด๋ฆ
# TF-IDF ํ๋ ฌ
matrix = rec.tfidf(data, col_contents)
# ์ฝ์ฌ์ธ ์ ์ฌ๋
similarity = rec.cos_similarity(data, col_contents)
# ์ถ์ฒ ์์คํ
title = '์ธํฐ์คํ
๋ผ' # col_title ์นผ๋ผ์ ๊ฐ ์ค ํ๋ ์ ํ
recommendations = rec.recommend(title, data, col_title, col_contents)
koda
ํ๊ตญ์ด ๋ฐ์ดํฐ ์ฆ๊ฐ์ ์ํ ๋ชจ๋
- synonym_replace(): ์ ์์ด ๋์ฒด
koda.synonym_replace(sentence)
- random_insert(): ๋จ์ด ๋๋ค ์ฝ์
koda.random_insert(sentence)
- random_swap(): ๋จ์ด ์๋ฆฌ ๋ฐ๊พธ๊ธฐ
koda.random_swap(sentence)
- random_delete(): ๋จ์ด ๋๋ค ์ญ์
koda.random_delete(sentence)
์์ ์ฝ๋
from babip import koda
# ์์ ๋ฌธ์ฅ
sentence = '๋กฏ๋ฐ ์์ด์ธ์ธ ์ ๋ํผ์ 16๋
์งธ ์
๊ณ ์๋ ์ ์ค์ฐ๋ ํฌ์คํธ์์ฆ ์ง์ถ์ด ๋๋ฌด๋๋ ๊ฐ์ ํ๋ค. ๊ทธ๋ "์ฌํด ์ฐ๋ฆฌ ํ์ด ๊ฐ์์ผ๊ตฌ์ ์ง์ถํ์ง ๋ชปํ๋ฉด ๋๋ฌด ์์ฌ์ธ ๊ฒ ๊ฐ๋ค"๊ณ ๋งํ๋ค.'
# ์ ์์ด ๋์ฒด
sr = koda.synonym_replace(sentence)
# ๋จ์ด ๋๋ค ์ฝ์
ri = koda.random_insert(sentence)
# ๋จ์ด ์๋ฆฌ ๋ฐ๊พธ๊ธฐ
rs = koda.random_swap(sentence)
# ๋จ์ด ๋๋ค ์ญ์
rd = koda.random_delete(sentence)
overfit
๊ณผ์ ํฉ ๋ฐฉ์ง๋ฅผ ์ํ ๋ชจ๋
- is_overfit(): ๊ณผ์ ํฉ ํ์ง
overfit.is_overfit(model, X_train, y_train, X_test, y_test)
์์ ์ฝ๋
from babip import overfit
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
# ๋ฐ์ดํฐ ๋ก๋
data_path = './../data.csv'
data = pd.read_csv(data_path)
# ๋ฐ์ดํฐ ๋ถํ
X = data['data']
Y = data['target']
X_train, X_test, y_train, y_test = train_test_split(X, Y, stratify=Y, random_state=777)
# ๋ชจ๋ธ ํ๋ จ
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
# ๊ณผ์ ํฉ ํ์ง
overfit_result = overfit.is_overfit(model, X_train, y_train, X_test, y_test)
hyperopt
ํ์ดํผํ๋ผ๋ฏธํฐ ์ต์ ํ๋ฅผ ์ํ ๋ชจ๋
- grid_search(): Grid Search๋ฅผ ํตํด ํ์ดํผํ๋ผ๋ฏธํฐ ์ต์ ํ
hyperopt.grid_search(model, parameters, X_train, y_train)
- random_search(): Random Search๋ฅผ ํตํด ํ์ดํผํ๋ผ๋ฏธํฐ ์ต์ ํ
hyperopt.random_search(model, parameters, X_train, y_train)
์์ ์ฝ๋
from babip import hyperopt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
# ๋ฐ์ดํฐ ๋ก๋
data_path = './../data.csv'
data = pd.read_csv(data_path)
# ๋ฐ์ดํฐ ๋ถํ
X = data['data']
Y = data['target']
X_train, X_test, y_train, y_test = train_test_split(X, Y, stratify=Y, random_state=777)
# ๋ชจ๋ธ ํ๋ จ
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
# ํ์ดํผํ๋ผ๋ฏธํฐ ํ์ ๊ตฌ๊ฐ ์ค์
parameters = {
'criterion': ['gini', 'entropy'],
'max_depth': [None, 2, 3, 4, 5, 6],
'max_leaf_nodes': range(5, 101, 5)
}
# Grid Search๋ฅผ ํตํด ์ต์ ์ ํ์ดํผํ๋ผ๋ฏธํฐ ๊ฐ ํ์
best_parameters_gs = hyperopt.grid_search(model, parameters, X_train, y_train)
# Random Search๋ฅผ ํตํด ์ต์ ์ ํ์ดํผํ๋ผ๋ฏธํฐ ๊ฐ ํ์
best_parameters_rs = hyperopt.random_search(model, parameters, X_train, y_train)