
๋น์ทํ ํ ์คํธ ๊ตฌ์ฑ์ ๋ฌธ์๋ฅผ ๊ตฐ์งํ ํ๋ ๊ฒ
๋ถ์ ํ๋ฆ
(1) ํ ์คํธ ์ ์ฒ๋ฆฌ
(2) ๋ฒกํฐํ
(3) ๊ตฐ์งํ ์๊ณ ๋ฆฌ์ฆ ์ ์ฉ
(4) cluster_centers(์ถ์ถ) ํตํด ๊ตฐ์ง๋ณ ํต์ฌ ๋จ์ด ์ถ์ถ
import pandas as pd
import glob, os
import warnings
warnings.filterwarnings('ignore')
pd.set_option('display.max_colwidth', 700)
# ์๋๋ ์ ์ปดํจํฐ์์ ์์ถ ํ์ผ์ ํ์ด ๋์ ๋๋ ํฐ๋ฆฌ์ด๋, ์ฌ๋ฌ๋ถ์ ๋๋ ํฐ๋ฆฌ๋ฅผ ์ค์ ํด ์ฃผ์ธ์
path = 'OpinosisDataset1.0/topics'
# path๋ก ์ง์ ํ ๋๋ ํฐ๋ฆฌ ๋ฐ์ ์๋ ๋ชจ๋ .data ํ์ผ๋ค์ ํ์ผ๋ช
์ ๋ฆฌ์คํธ๋ก ์ทจํฉ
all_files = glob.glob(os.path.join(path, "*.data"))
filename_list = []
opinion_text = []
# ๊ฐ๋ณ ํ์ผ๋ค์ ํ์ผ๋ช
์ filename_list ๋ฆฌ์คํธ๋ก ์ทจํฉ,
# ๊ฐ๋ณ ํ์ผ๋ค์ ํ์ผ ๋ด์ฉ์ DataFrame ๋ก๋ฉ ํ ๋ค์ string์ผ๋ก ๋ณํํ์ฌ opinion_text ๋ฆฌ์คํธ๋ก ์ทจํฉ
for file_ in all_files:
# ๊ฐ๋ณ ํ์ผ์ ์ฝ์ด์ DataFrame์ผ๋ก ์์ฑ
df = pd.read_table(file_,index_col=None, header=0,encoding='latin1')
# ์ ๋๊ฒฝ๋ก๋ก ์ฃผ์ด์ง file ๋ช
์ ๊ฐ๊ณต. ๋ง์ผ Linux์์ ์ํ์์๋ ์๋ \\๋ฅผ / ๋ณ๊ฒฝ.
# ๋งจ ๋ง์ง๋ง .data ํ์ฅ์๋ ์ ๊ฑฐ
filename_ = file_.split('\\')[-1]
filename = filename_.split('.')[0]
# ํ์ผ๋ช
๋ฆฌ์คํธ์ ํ์ผ ๋ด์ฉ ๋ฆฌ์คํธ์ ํ์ผ๋ช
๊ณผ ํ์ผ ๋ด์ฉ์ ์ถ๊ฐ.
filename_list.append(filename)
opinion_text.append(df.to_string())
# ํ์ผ๋ช
๋ฆฌ์คํธ์ ํ์ผ ๋ด์ฉ ๋ฆฌ์คํธ๋ฅผ DataFrame์ผ๋ก ์์ฑ
document_df = pd.DataFrame({'filename':filename_list, 'opinion_text':opinion_text})
document_df.head()
tfIdfVectorizer์ tokenizer ์ธ์๋ก ์ฌ์ฉ๋ lemmatization ์ด๊ทผ ๋ณํ ํจ์๋ฅผ ์ค์
์์ฑ LemNormalize ํจ์ ์ค์
from nltk.stem import WordNetLemmatizer
import nltk
import string
remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation)
lemmar = WordNetLemmatizer()
# ์
๋ ฅ์ผ๋ก ๋ค์ด์จ token๋จ์ด๋ค์ ๋ํด์ lemmatization ์ด๊ทผ ๋ณํ.
def LemTokens(tokens):
return [lemmar.lemmatize(token) for token in tokens]
# TfidfVectorizer ๊ฐ์ฒด ์์ฑ ์ tokenizer์ธ์๋ก ํด๋น ํจ์๋ฅผ ์ค์ ํ์ฌ lemmatization ์ ์ฉ
# ์
๋ ฅ์ผ๋ก ๋ฌธ์ฅ์ ๋ฐ์์ stop words ์ ๊ฑฐ-> ์๋ฌธ์ ๋ณํ -> ๋จ์ด ํ ํฐํ -> lemmatization ์ด๊ทผ ๋ณํ.
def LemNormalize(text):
return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))
๊ตฐ์ง์ด ๊ฐ ์ฃผ์ ๋ณ๋ก ์ ์ฌํ ํํ๋ก ์ ๊ตฌ์ฑ๋๋์ง
๋ฌธ์๋ณ๋ก ํ
์คํธ๊ฐ TF-IDF ๋ณํ๋ ํผ์ฒ ๋ฒกํฐ์ ํ๋ ฌ ๋ฐ์ดํฐ์ ๋ํด ๊ตฐ์งํ๋ฅผ ์ํํด ์ด๋ค ๋ฌธ์๋ผ๋ฆฌ ๊ตฐ์ง๋๋์ง ํ์ธ
from sklearn.cluster import KMeans
# 5๊ฐ ์งํฉ์ผ๋ก ๊ตฐ์งํ ์ํ. ์์ ๋ฅผ ์ํด ๋์ผํ ํด๋ฌ์คํฐ๋ง ๊ฒฐ๊ณผ ๋์ถ์ฉ random_state=0
km_cluster = KMeans(n_clusters=5, max_iter=10000, random_state=0)
km_cluster.fit(feature_vect)
cluster_label = km_cluster.labels_
cluster_centers = km_cluster.cluster_centers_
๊ตฐ์ง๋ณ ํต์ฌ๋จ์ด ์ถ์ถ
๊ฐ ๊ตฐ์ง์ ์๊ฐ ๋ฌธ์๋ ํต์ฌ๋จ์ด๋ฅผ ์ฃผ์ถ์ผ๋ก ๊ตฐ์งํ๋์ด ์์
๊ฐ ๊ตฐ์ง์ ๊ตฌ์ฑํ๋ ํต์ฌ ๋จ์ด ํ์ธ
cluster_centers = km_cluster.cluster_centers_
print('cluster_centers shape :',cluster_centers.shape)
print(cluster_centers)
Cluster_centers_ ์์ฑ๊ฐ์ ์ด์ฉํด ๊ฐ ๊ตฐ์ง๋ณ ํต์ฌ ๋จ์ด ์ฐพ๊ธฐ# ๊ตฐ์ง๋ณ top n ํต์ฌ๋จ์ด, ๊ทธ ๋จ์ด์ ์ค์ฌ ์์น ์๋๊ฐ, ๋์ ํ์ผ๋ช
๋ค์ ๋ฐํํจ.
def get_cluster_details(cluster_model, cluster_data, feature_names, clusters_num, top_n_features=10):
cluster_details = {}
# cluster_centers array ์ ๊ฐ์ด ํฐ ์์ผ๋ก ์ ๋ ฌ๋ index ๊ฐ์ ๋ฐํ
# ๊ตฐ์ง ์ค์ฌ์ (centroid)๋ณ ํ ๋น๋ word ํผ์ฒ๋ค์ ๊ฑฐ๋ฆฌ๊ฐ์ด ํฐ ์์ผ๋ก ๊ฐ์ ๊ตฌํ๊ธฐ ์ํจ.
centroid_feature_ordered_ind = cluster_model.cluster_centers_.argsort()[:,::-1]
#๊ฐ๋ณ ๊ตฐ์ง๋ณ๋ก iterationํ๋ฉด์ ํต์ฌ๋จ์ด, ๊ทธ ๋จ์ด์ ์ค์ฌ ์์น ์๋๊ฐ, ๋์ ํ์ผ๋ช
์
๋ ฅ
for cluster_num in range(clusters_num):
# ๊ฐ๋ณ ๊ตฐ์ง๋ณ ์ ๋ณด๋ฅผ ๋ด์ ๋ฐ์ดํฐ ์ด๊ธฐํ.
cluster_details[cluster_num] = {}
cluster_details[cluster_num]['cluster'] = cluster_num
# cluster_centers_.argsort()[:,::-1] ๋ก ๊ตฌํ index ๋ฅผ ์ด์ฉํ์ฌ top n ํผ์ฒ ๋จ์ด๋ฅผ ๊ตฌํจ.
top_feature_indexes = centroid_feature_ordered_ind[cluster_num, :top_n_features]
top_features = [ feature_names[ind] for ind in top_feature_indexes ]
# top_feature_indexes๋ฅผ ์ด์ฉํด ํด๋น ํผ์ฒ ๋จ์ด์ ์ค์ฌ ์์น ์๋๊ฐ ๊ตฌํจ
top_feature_values = cluster_model.cluster_centers_[cluster_num, top_feature_indexes].tolist()
# cluster_details ๋์
๋๋ฆฌ ๊ฐ์ฒด์ ๊ฐ๋ณ ๊ตฐ์ง๋ณ ํต์ฌ ๋จ์ด์ ์ค์ฌ์์น ์๋๊ฐ, ๊ทธ๋ฆฌ๊ณ ํด๋น ํ์ผ๋ช
์
๋ ฅ
cluster_details[cluster_num]['top_features'] = top_features
cluster_details[cluster_num]['top_features_value'] = top_feature_values
filenames = cluster_data[cluster_data['cluster_label'] == cluster_num]['filename']
filenames = filenames.values.tolist()
cluster_details[cluster_num]['filenames'] = filenames
return cluster_details
๋ฒกํฐ์ ๋ฒกํฐ ๊ฐ์ ์ ์ฌ๋๋ฅผ ๋น๊ตํ ๋ ๋ฒกํฐ์ ํฌ๊ธฐ๋ณด๋ค๋ ๋ฒกํฐ์ ์ํธ ๋ฐฉํฅ์ฑ์ด ์ผ๋ง๋ ์ ์ฌํ์ง
์ฝ์ฌ์ธ ์ ์ฌ๋๋ ๋ ๋ฒกํฐ์ ์ฌ์๊ฐ์ ๊ตฌํด์ ์ผ๋ง๋ ์ ์ฌํ์ง ์์น๋ก ์ ์ฉ

๋ฌธ์ ์ ์ฌ๋๋ฅผ ์ธก์ ํ๋ ์ฌ์ดํท๋ฐ API
from sklearn.metrics.pairwise import cosine_similarity
Cosine_similarity()
2๊ฐ์ ์
๋ ฅ ํ๋ผ๋ฏธํฐ
ํฌ์ ํ๋ ฌ, ๋ฐ์ง ํ๋ ฌ ๋ชจ๋ ๊ฐ๋ฅ, ํ๋ ฌ ๋๋ ๋ฐฐ์ด ๋ชจ๋ ๊ฐ๋ฅ
์์ผ๋ก ์ฝ์ฌ์ธ ์ ์ฌ๋ ๊ฐ ์ ๊ณต ndarray ์ ๊ณต
from nltk.stem import WordNetLemmatizer
import nltk
import string
remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation)
lemmar = WordNetLemmatizer()
# ์
๋ ฅ์ผ๋ก ๋ค์ด์จ token๋จ์ด๋ค์ ๋ํด์ lemmatization ์ด๊ทผ ๋ณํ.
def LemTokens(tokens):
return [lemmar.lemmatize(token) for token in tokens]
# TfidfVectorizer ๊ฐ์ฒด ์์ฑ ์ tokenizer์ธ์๋ก ํด๋น ํจ์๋ฅผ ์ค์ ํ์ฌ lemmatization ์ ์ฉ
# ์
๋ ฅ์ผ๋ก ๋ฌธ์ฅ์ ๋ฐ์์ stop words ์ ๊ฑฐ-> ์๋ฌธ์ ๋ณํ -> ๋จ์ด ํ ํฐํ -> lemmatization ์ด๊ทผ ๋ณํ.
def LemNormalize(text):
return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))
import pandas as pd
import glob, os
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cluster import KMeans
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
from nltk.tokenize import word_tokenize
import warnings
warnings.filterwarnings('ignore')
# Define a lemmatization function
def LemNormalize(text):
lemmatizer = WordNetLemmatizer()
stop_words = set(stopwords.words('english'))
words = word_tokenize(text)
return ' '.join([lemmatizer.lemmatize(word) for word in words if word.lower() not in stop_words])
path = r'OpinosisDataset1.0\topics'
all_files = glob.glob(os.path.join(path, "*.data"))
filename_list = []
opinion_text = []
for file_ in all_files:
df = pd.read_table(file_, index_col=None, header=0, encoding='latin1')
filename_ = file_.split('\\')[-1]
filename = filename_.split('.')[0]
filename_list.append(filename)
opinion_text.append(df.to_string())
document_df = pd.DataFrame({'filename': filename_list, 'opinion_text': opinion_text})
tfidf_vect = TfidfVectorizer(tokenizer=LemNormalize, stop_words='english', \
ngram_range=(1, 2), min_df=0.05, max_df=0.85)
feature_vect = tfidf_vect.fit_transform(document_df['opinion_text'])
km_cluster = KMeans(n_clusters=3, max_iter=10000, random_state=0)
km_cluster.fit(feature_vect)
cluster_label = km_cluster.labels_
cluster_centers = km_cluster.cluster_centers_
document_df['cluster_label'] = cluster_label
ํธํ
์ ์ฃผ์ ๋ก ๊ตฐ์งํ๋ ๋ฌธ์๋ฅผ ์ด์ฉํด ํน์ ๋ฌธ์์ ๋ค๋ฅธ ๋ฌธ์ ๊ฐ์ ์ ์ฌ๋ ์ธก์
ํธํ
์ ์ฃผ์ ๋ก ๊ตฐ์งํ๋ ๋ฐ์ดํฐ ๋จผ์ ์ถ์ถ, ์ด ๋ฐ์ดํฐ์ ํด๋นํ๋ TfidfVectorizer์ ๋ฐ์ดํฐ ์ถ์ถ
ํ๊ธ ์ธ์ด ์ฒ๋ฆฌ๊ฐ ์์ด ๋ฑ์ ๋ผํด์ด ์ฒ๋ฆฌ๋ณด๋ค ์ด๋ ค์ด ์ด์ - ๋์ด์ฐ๊ธฐ, ๋ค์ํ ์กฐ์ฌ
ํ์ด์ฌ์ ๋ํ์ ์ธ ํ๊ธ ํํ์ ํจํค์ง
์คํ ์์ค ํ๊ตญ์ด ํํ์ ๋ถ์๊ธฐ
ํ๋๋์ด๋ ๊ผฌ๊ผฌ๋ง ๋ฑ์ ๊ธฐ์กด ํํ์ ๋ถ์๊ธฐ์ ๋์ด์ฐ๊ธฐ ๊ตฌ๋ถ์ ์ค๋ฅ๋ ๊ณต๊ฐ ์์ค๋ฅผ ๊ตฌํ๊ธฐ ์ด๋ ต๋ค๋ ๋ฌธ์ ๋ฅผ ๊ทน๋ณตํ๊ธฐ ์ํด ์์๋จ
์ํ๋ ๋จ์ด๊ฐ ํํ์ ๋ถ์์ผ๋ก tagging์ด ์๋ ๋ ํํ์ ๋ถ์๊ธฐ์์ ์ฌ์ฉ์ ์ฌ์ ์ ๊ตฌ์ถํด ํด๋น ๋จ์ด๊ฐ ํํ์ ๋ถ์๊ธฐ์ tagging์ด ๋ ์ ์๋๋ก ํ ์ ์์
๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ
Train_df์ด ์กด์ฌํ๋ Null์ ๊ณต๋ฐฑ์ผ๋ก ๋ณํ
์ซ์์ ๊ฒฝ์ฐ ๋จ์ด์ ์ธ ์๋ฏธ๊ฐ ๋ถ์กฑํ๋ฏ๋ก ํ์ด์ฌ ์ ๊ท ํํ์ ๋ชจ๋ re๋ฅผ ์ด์ฉํด ๊ณต๋ฐฑ์ผ๋ก ๋ณํ
import re
# document ๊ฒฐ์ธก ๊ณต๋ฐฑ์ผ๋ก ๋ณํ
train_df = train_df.fillna(" ")
# ์ ๊ท ํํ์์ผ๋ก ์ซ์๋ฅผ ๊ณต๋ฐฑ์ผ๋ก ๋ณ๊ฒฝ (์ ๊ท ํํ์์์ \d๋ ์ซ์๋ฅผ ์๋ฏธ)
train_df["document"] = train_df["document"].apply(lambda x: re.sub(r"\d+", " ", x))
# test set ๋์ผ ์์
test_df = pd.read_csv('nsmc-master/ratings_test.txt', sep='\t')
test_df = test_df.fillna(" ")
test_df["document"] = test_df["document"].apply(lambda x: re.sub(r"\d+", " ", x))
# id ์ปฌ๋ผ ์ ๊ฑฐ
train_df.drop("id", axis=1, inplace=True)
test_df.drop("id", axis=1, inplace=True)
SNS ๋ถ์์ ์ ํฉํ Twitter ํด๋์ค๋ฅผ ํ๊ธ ํํ์ ์์ง์ผ๋ก ์ด์ฉ
Twitter ๊ฐ์ฒด์ morphs() ๋ฉ์๋๋ฅผ ์ด์ฉํ๋ฉด ์
๋ ฅ์ธ์๋ก ๋ค์ด์จ ๋ฌธ์ฅ์ ํํ์ ๋จ์ด ํํ๋ก ํ ํฐํ ํด list ๊ฐ์ฒด๋ก ๋ฐํ
from konlpy.tag import Twitter
twitter = Twitter()
def tw_tokenizer(text):
# ํ
์คํธ๋ฅผ ํํ์ ๋จ์ด๋ก ํ ํฐํ ํ ๋ฆฌ์คํธ๋ก ๋ฐํ
tokens_ko = twitter.morphs(text)
return tokens_ko
์ฌ์ดํท๋ฐ์ TfidfVectorizer๋ฅผ ์ด์ฉํด TF-IDF ํผ์ฒ ๋ชจ๋ธ์ ์์ฑ
๋ก์ง์คํฑ ํ๊ท๋ฅผ ์ด์ฉํด ๋ถ๋ฅ ๊ธฐ๋ฐ์ ๊ฐ์ ๋ถ์์ ์ํ
๋ก์ง์คํฑ ํ๊ท์ ํ์ดํผํ๋ผ๋ฏธํฐ c ์ต์ ํ๋ฅผ ์ํด GridSearchCV๋ฅผ ์ด์ฉ
# GridSearchCV
params = {
"lr_clf__C": [1, 3.5, 10]
}
grid_cv = GridSearchCV(pipeline, param_grid=params, scoring="accuracy", verbose=1)
grid_cv.fit(train_df['document'], train_df['label'])
print(grid_cv.best_params_, round(grid_cv.best_score_,4))
from sklearn.metrics import accuracy_score
# ์์ธก/ํ๊ฐ (best_estimator๋ก ์ํด๋ ์ด๋ฏธ ์ต์ ์ผ๋ก ํ์ต๋์ด ์์)
best_estimator = grid_cv.best_estimator_
pred = best_estimator.predict(test_df["document"])
acc = accuracy_score(test_df["label"], pred)
print(f"Logistic Regression ์ ํ๋: {acc:.4f}")

from sklearn.linear_model import Ridge, LogisticRegression
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer
import pandas as pd
mercari_df = pd.read_csv('train.tsv', sep='\t')
mercari_df.head(3)

๊ฐ๊ฒฉ์ ์ํฅ์ ๋ฏธ์น๋ ์ค์ ์์ธ์ธ brand_name์ด ๋ง์ Null์ ๊ฐ์ง๊ณ ์์

Price ๊ฐ์ด ๋น๊ต์ ์ ์ ๊ฐ๊ฒฉ์ ๋ฐ์ดํฐ ๊ฐ์ ์๊ณก๋ผ ๋ถํฌ
๋ก๊ทธ ๊ฐ์ผ๋ก ๋ณํํด ์ ๊ท ๋ถํฌ ํํ๋ก ๋ณํ

mercari_df['price']= np.log1p(mercari_df['price'])
mercari_df['price'].head(3)
category_name์ '/'๋ฅผ ๊ธฐ์ค์ผ๋ก ๋จ์ด ํ ํฐํ ํ ๊ฐ๊ฐ ๋ณ๋ ํผ์ฒ๋ก ์ ์ฅ
Null์ด ์๋ ๊ฒฝ์ฐ split("/")์ ์ด์ฉํด ๋, ์ค, ์๋ถ๋ฅ๋ฅผ ๋ถ๋ฆฌ (๋ฆฌ์คํธ๋ก ๋ฐํ)
Null ์ผ๊ฒฝ์ฐ except catch ํ์ฌ ๋, ์ค, ์๋ถ๋ฅ ๋ชจ๋ 'Other Null' ๊ฐ์ ๋ถ์ฌ
#apply lambda์์ ํธ์ถ๋๋ ๋, ์ค, ์ ๋ถํ ํจ์ ์์ฑ, ๋, ์ค, ์ ๊ฐ์ ๋ฆฌ์คํธ๋ก ๋ณํ
def split_cat(category_name):
try:
return category_name.split('/')
except:
return ['Other_Null', 'Other_Null', 'Other_Null']
#์์ split_cat()์ apply lambda์์ ํธ์ถํด ๋,์ค,์ ์นผ๋ผ์ mercari_df์ ์์ฑ.
mercari_df['cat_dae'], mercari_df['cat_jung'], mercari_df['cat_so'] = zip(*mercari_df['category_name'].apply(
lambda x : split_cat(x)))
print("๋๋ถ๋ฅ ์ ํ :\n", mercari_df['cat_dae'].value_counts())
print("์ค๋ถ๋ฅ ๊ฐ์ :", mercari_df['cat_jung'].nunique())
print("์๋ถ๋ฅ ๊ฐ์ ", mercari_df['cat_so'].nunique())
mercari_df['brand_name'] = mercari_df['brand_name'].fillna(value='Other_Null')
mercari_df['category_name'] = mercari_df['category_name'].fillna(value='Other_Null')
mercari_df['item_description'] = mercari_df['item_description'].fillna(value='Other_Null')
# ๊ฐ ์นผ๋ผ๋ณ๋ก Null ๊ฐ ๊ฑด์ ํ์ธ. ๋ชจ๋ 0์ด ๋์์ผ ํฉ๋๋ค.
mercari_df.isnull().sum()
๋ณธ ๋ํ์์ ์์ธก ๋ชจ๋ธ์ ์ํ ๊ฐ๊ฒฉ์ ์์ธกํด์ผ ํ๋ฏ๋ก ํ๊ท ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก ํจ
์ ํ ํ๊ท์์๋ ์-ํซ ์ธ์ฝ๋ฉ ์ ํธ
ํผ์ฒ ๋ฒกํฐํ์ ๊ฒฝ์ฐ ์งง์ ํ
์คํธ - Count ๊ธฐ๋ฐ ๋ฒกํฐํ
๊ธด ํ
์คํธ - TF-IDF ๊ธฐ๋ฐ ๋ฒกํฐํ ์ ์ฉ
์์ธก๋ price๊ฐ์ ๋ค์ ์ง์ ๋ณํ์ ํตํด ์๋ณตํด์ผ ํจ
Evaluate_org_price(y_text, preds) ์๋ณต๋ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก RMSLE๋ฅผ ์ ์ฉ
linear_model = Ridge(solver="lsqr", fit_intercept=False)
sparse_matrix_list = (X_name, X_brand, X_item_cond_id,
X_shipping, X_cat_dae, X_cat_jung, X_cat_so)
linear_preds, y_test = model_train_predict(model=linear_model, matrix_list = sparse_matrix_list)
print('Item Description์ ์ ์ธํ์ ๋ rmsle ๊ฐ:', evaluate_org_price(y_test, linear_preds))
sparse_matrix_list = (X_descp, X_name, X_brand, X_item_cond_id,
X_shipping, X_cat_dae, X_cat_jung, X_cat_so)
linear_preds, y_test = model_train_predict(model = linear_model, matrix_list = sparse_matrix_list)
print('Item Description์ ํฌํจํ rmsle ๊ฐ:', evaluate_org_price(y_test, linear_preds))
LightGBM์ ์ด์ฉํด ํ๊ท ์ํํ ๋ค ์์ ๊ตฌํ ๋ฆฟ์ง๋ชจ๋ธ ์์ธก๊ฐ๊ณผ LightGBM ๋ชจ๋ธ ์์ธก๊ฐ์ ๊ฐ๋จํ ์์๋ธ ๋ฐฉ์์ผ๋ก ์์ด์ ์ต์ข ํ๊ท ์์ธก๊ฐ์ ํ๊ฐ
from lightgbm import LGBMRegressor
sparse_matrix_list = (X_descp, X_name, X_brand, X_item_cond_id,
X_shipping, X_cat_dae, X_cat_jung, X_cat_so)
lgbm_model = LGBMRegressor(n_estimators=200, learning_rate=0.5, num_leaves=125, random_state=156)
lgbm_preds, y_test = model_train_predict(model = lgbm_model, matrix_list= sparse_matrix_list)
print('LightGBM rmsle ๊ฐ:', evaluate_org_price(y_test, lgbm_preds))
preds = lgbm_preds*0.45 + linear_preds*0.55
print('LightGBM๊ณผ Ridge๋ฅผ ensembleํ ์ต์ข
rmsle ๊ฐ:', evaluate_org_price(y_test, preds))