From b3730d315829930822d4f6d1159170a4fed00c4c Mon Sep 17 00:00:00 2001 From: ektmf7890 Date: Sat, 16 Jan 2021 12:56:09 +0900 Subject: [PATCH] added Project folder --- .../Content_Based-checkpoint.ipynb | 114 ++++++++++++++++-- .../TripRecommender-checkpoint.ipynb | 6 + ProjectFolder/TripRecommender.ipynb | 32 +++++ Recommender.py | 20 +++ ...5\264\355\230\234\353\246\274_crawling.py" | 1 + 5 files changed, 162 insertions(+), 11 deletions(-) create mode 100644 ProjectFolder/.ipynb_checkpoints/TripRecommender-checkpoint.ipynb create mode 100644 ProjectFolder/TripRecommender.ipynb diff --git a/.ipynb_checkpoints/Content_Based-checkpoint.ipynb b/.ipynb_checkpoints/Content_Based-checkpoint.ipynb index 13e2276..ea7b313 100644 --- a/.ipynb_checkpoints/Content_Based-checkpoint.ipynb +++ b/.ipynb_checkpoints/Content_Based-checkpoint.ipynb @@ -6,6 +6,7 @@ "metadata": {}, "outputs": [], "source": [ + "import numpy as np\n", "import pandas as pd\n", "from ast import literal_eval" ] @@ -97,7 +98,9 @@ { "cell_type": "code", "execution_count": 4, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "data": { @@ -275,6 +278,47 @@ "print(f'CountVectorizer가 찾은 장르 갯수: {len(cv.get_feature_names())}')" ] }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['action',\n", + " 'adventure',\n", + " 'animation',\n", + " 'comedy',\n", + " 'crime',\n", + " 'documentary',\n", + " 'drama',\n", + " 'family',\n", + " 'fantasy',\n", + " 'fiction',\n", + " 'foreign',\n", + " 'history',\n", + " 'horror',\n", + " 'movie',\n", + " 'music',\n", + " 'mystery',\n", + " 'romance',\n", + " 'science',\n", + " 'thriller',\n", + " 'tv',\n", + " 'war',\n", + " 'western']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cv.get_feature_names()" + ] + }, { "cell_type": "code", "execution_count": 8, @@ -324,7 +368,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -334,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -355,7 +399,7 @@ " 1. ]])" ] }, - "execution_count": 14, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -366,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -375,7 +419,7 @@ "(4803, 4803)" ] }, - "execution_count": 15, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -386,11 +430,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ - "def get_recommend_movie_list(df, movie_title, top=30):\n", + "titles = data['title']\n", + "indices = pd.Series(data.index, index=data['title'])\n", + "\n", + "def get_recommend_movie_list(title, top=30):\n", + " index = indices[title]\n", + " sim_scores = list(enumerate(similartiy_matrix[index]))\n", + " sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True)\n", + " sim_scores = sim_scores[1:top+1]\n", + " movie_indices = [i[0] for i in sim_scores]\n", + " return titles.iloc[movie_indices]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5 Spider-Man 3\n", + "9 Batman v Superman: Dawn of Justice\n", + "Name: title, dtype: object" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_recommend_movie_list('Pirates of the Caribbean: At World\\'s End',2 )" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unexpected EOF while parsing (, line 3)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m \u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n" + ] + } + ], + "source": [ + "# 사용자에게 영화 리뷰를 입력받고 추천 리스트를 출력해주는 함수\n", + "def recommend():\n", " " ] }, @@ -399,9 +493,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "def " - ] + "source": [] } ], "metadata": { diff --git a/ProjectFolder/.ipynb_checkpoints/TripRecommender-checkpoint.ipynb b/ProjectFolder/.ipynb_checkpoints/TripRecommender-checkpoint.ipynb new file mode 100644 index 0000000..7fec515 --- /dev/null +++ b/ProjectFolder/.ipynb_checkpoints/TripRecommender-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/ProjectFolder/TripRecommender.ipynb b/ProjectFolder/TripRecommender.ipynb new file mode 100644 index 0000000..34f374f --- /dev/null +++ b/ProjectFolder/TripRecommender.ipynb @@ -0,0 +1,32 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/Recommender.py b/Recommender.py index 3e64729..8c79a85 100644 --- a/Recommender.py +++ b/Recommender.py @@ -24,3 +24,23 @@ #코사인 유사도 계산 from sklearn.metrics.pairwise import cosine_similarity similartiy_matrix = cosine_similarity(c_vector_genres, c_vector_genres) + +titles = data['title'] +indices = pd.Series(data.index, index=data['title']) + +def get_recommend_movie_list(title, top=30): + index = indices[title] + sim_scores = list(enumerate(similartiy_matrix[index])) + sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True) + sim_scores = sim_scores[1:top+1] + movie_indices = [i[0] for i in sim_scores] + return titles.iloc[movie_indices] + +# 사용자에게 영화 리뷰를 입력받고 추천 리스트를 출력해주는 함수 +def recommend(): + print("킁") + + +if __name__ == '__main__': + recommend() + diff --git "a/\354\235\264\355\230\234\353\246\274_crawling.py" "b/\354\235\264\355\230\234\353\246\274_crawling.py" index 332afc3..26207a4 100644 --- "a/\354\235\264\355\230\234\353\246\274_crawling.py" +++ "b/\354\235\264\355\230\234\353\246\274_crawling.py" @@ -10,6 +10,7 @@ driver = webdriver.Chrome(ChromeDriverManager().install()) driver.implicitly_wait(25) +search_list = [] #main for i in range(6, 12):