{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f8a0aaf5", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import string\n", "from sklearn.metrics.pairwise import cosine_similarity\n", "from sklearn.feature_extraction.text import CountVectorizer" ] }, { "cell_type": "code", "execution_count": 2, "id": "b11461ce", "metadata": {}, "outputs": [], "source": [ "# Load the datasets\n", "events = pd.read_json(\"../dataset/events.json\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "ddad7602", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
event_idtitledescriptiontagstypelocationorganizationNameisPaidprice
068e0d68abee8a0e226e6fe96Versatile homogeneous interfaceOption their account pattern center challenge....[web development, AI]ForumJaclynboroughLopez and SonsFalse0.0
\n", "
" ], "text/plain": [ " event_id title \\\n", "0 68e0d68abee8a0e226e6fe96 Versatile homogeneous interface \n", "\n", " description tags \\\n", "0 Option their account pattern center challenge.... [web development, AI] \n", "\n", " type location organizationName isPaid price \n", "0 Forum Jaclynborough Lopez and Sons False 0.0 " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "events.head(1)" ] }, { "cell_type": "code", "execution_count": 4, "id": "78924dac", "metadata": {}, "outputs": [], "source": [ "#combining all strings column\n", "events['Keywords']= events['title'] + '_' + events['location'] + '_' + events['organizationName'] + '_' + events['type']" ] }, { "cell_type": "code", "execution_count": 5, "id": "abd11fee", "metadata": {}, "outputs": [], "source": [ "#deleting all these added columns\n", "events.drop(columns=['title', 'location', 'organizationName', 'type', 'isPaid', 'price'], inplace=True)" ] }, { "cell_type": "code", "execution_count": 6, "id": "0e1d7ae1", "metadata": {}, "outputs": [], "source": [ "#converting the string column into a list column\n", "events['Keywords'] = events['Keywords'].apply(lambda x: x.split('_'))" ] }, { "cell_type": "code", "execution_count": 7, "id": "1c703e42", "metadata": {}, "outputs": [], "source": [ "#combining the keywords and tags columns\n", "#then deleting them\n", "events['keywords']= events['Keywords'] + events['tags'] \n", "events.drop(columns=['Keywords', 'tags'], inplace=True)" ] }, { "cell_type": "code", "execution_count": 8, "id": "127c3919", "metadata": {}, "outputs": [], "source": [ "#deleting the isPaid column (already deleted above, so this cell can be skipped or left empty)" ] }, { "cell_type": "code", "execution_count": 9, "id": "193f704c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
event_iddescriptionkeywords
068e0d68abee8a0e226e6fe96Option their account pattern center challenge....[Versatile homogeneous interface, Jaclynboroug...
168e0d68abee8a0e226e6fe97Evening whom much could. Send rock important i...[Intuitive empowering orchestration, New Maria...
268e0d68abee8a0e226e6fe98Maintain however soldier happen answer already...[Reduced content-based product, Port Alexis, S...
368e0d68abee8a0e226e6fe99Inside stop bit student many identify internat...[Object-based intermediate artificial intellig...
468e0d68abee8a0e226e6fe9aAvailable ground treat film maybe himself pres...[Grass-roots global hub, New Chrisport, Fletch...
\n", "
" ], "text/plain": [ " event_id \\\n", "0 68e0d68abee8a0e226e6fe96 \n", "1 68e0d68abee8a0e226e6fe97 \n", "2 68e0d68abee8a0e226e6fe98 \n", "3 68e0d68abee8a0e226e6fe99 \n", "4 68e0d68abee8a0e226e6fe9a \n", "\n", " description \\\n", "0 Option their account pattern center challenge.... \n", "1 Evening whom much could. Send rock important i... \n", "2 Maintain however soldier happen answer already... \n", "3 Inside stop bit student many identify internat... \n", "4 Available ground treat film maybe himself pres... \n", "\n", " keywords \n", "0 [Versatile homogeneous interface, Jaclynboroug... \n", "1 [Intuitive empowering orchestration, New Maria... \n", "2 [Reduced content-based product, Port Alexis, S... \n", "3 [Object-based intermediate artificial intellig... \n", "4 [Grass-roots global hub, New Chrisport, Fletch... " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "events.head(5)" ] }, { "cell_type": "code", "execution_count": 10, "id": "d68c603b", "metadata": {}, "outputs": [], "source": [ "#converting the description column into a list column\n", "events['description'] = events['description'].apply(lambda x: x.split(' '))" ] }, { "cell_type": "code", "execution_count": 11, "id": "09a314a6", "metadata": {}, "outputs": [], "source": [ "#combining the keywords and description columns\n", "#then deleting them\n", "events['key']= events['keywords'] + events['description']\n", "events.drop(columns=['keywords', 'description'], inplace=True)" ] }, { "cell_type": "code", "execution_count": 12, "id": "58b7de88", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
event_idkey
068e0d68abee8a0e226e6fe96[Versatile homogeneous interface, Jaclynboroug...
168e0d68abee8a0e226e6fe97[Intuitive empowering orchestration, New Maria...
268e0d68abee8a0e226e6fe98[Reduced content-based product, Port Alexis, S...
368e0d68abee8a0e226e6fe99[Object-based intermediate artificial intellig...
468e0d68abee8a0e226e6fe9a[Grass-roots global hub, New Chrisport, Fletch...
.........
41568e0d79a3048252621b7d95c[Extended full-range open system, New Carrie, ...
41668e0d79a3048252621b7d95d[Polarized discrete benchmark, Lake Stacyport,...
41768e0d79a3048252621b7d95e[Proactive reciprocal challenge, Walkerview, S...
41868e0d79a3048252621b7d95f[Grass-roots secondary forecast, Andrewberg, M...
41968e0d79a3048252621b7d960[Integrated actuating infrastructure, New Eric...
\n", "

420 rows × 2 columns

\n", "
" ], "text/plain": [ " event_id \\\n", "0 68e0d68abee8a0e226e6fe96 \n", "1 68e0d68abee8a0e226e6fe97 \n", "2 68e0d68abee8a0e226e6fe98 \n", "3 68e0d68abee8a0e226e6fe99 \n", "4 68e0d68abee8a0e226e6fe9a \n", ".. ... \n", "415 68e0d79a3048252621b7d95c \n", "416 68e0d79a3048252621b7d95d \n", "417 68e0d79a3048252621b7d95e \n", "418 68e0d79a3048252621b7d95f \n", "419 68e0d79a3048252621b7d960 \n", "\n", " key \n", "0 [Versatile homogeneous interface, Jaclynboroug... \n", "1 [Intuitive empowering orchestration, New Maria... \n", "2 [Reduced content-based product, Port Alexis, S... \n", "3 [Object-based intermediate artificial intellig... \n", "4 [Grass-roots global hub, New Chrisport, Fletch... \n", ".. ... \n", "415 [Extended full-range open system, New Carrie, ... \n", "416 [Polarized discrete benchmark, Lake Stacyport,... \n", "417 [Proactive reciprocal challenge, Walkerview, S... \n", "418 [Grass-roots secondary forecast, Andrewberg, M... \n", "419 [Integrated actuating infrastructure, New Eric... \n", "\n", "[420 rows x 2 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "events" ] }, { "cell_type": "code", "execution_count": 13, "id": "45e68d13", "metadata": {}, "outputs": [], "source": [ "#converting list to string for vectorization\n", "events['key']= events['key'].apply(lambda x:\" \".join(x) if isinstance(x, list) else str(x))" ] }, { "cell_type": "code", "execution_count": 14, "id": "f2f1683e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
event_idkey
068e0d68abee8a0e226e6fe96Versatile homogeneous interface Jaclynborough ...
168e0d68abee8a0e226e6fe97Intuitive empowering orchestration New Mariabe...
268e0d68abee8a0e226e6fe98Reduced content-based product Port Alexis Ston...
368e0d68abee8a0e226e6fe99Object-based intermediate artificial intellige...
468e0d68abee8a0e226e6fe9aGrass-roots global hub New Chrisport Fletcher-...
.........
41568e0d79a3048252621b7d95cExtended full-range open system New Carrie Whi...
41668e0d79a3048252621b7d95dPolarized discrete benchmark Lake Stacyport Mo...
41768e0d79a3048252621b7d95eProactive reciprocal challenge Walkerview Scot...
41868e0d79a3048252621b7d95fGrass-roots secondary forecast Andrewberg More...
41968e0d79a3048252621b7d960Integrated actuating infrastructure New Erica ...
\n", "

420 rows × 2 columns

\n", "
" ], "text/plain": [ " event_id \\\n", "0 68e0d68abee8a0e226e6fe96 \n", "1 68e0d68abee8a0e226e6fe97 \n", "2 68e0d68abee8a0e226e6fe98 \n", "3 68e0d68abee8a0e226e6fe99 \n", "4 68e0d68abee8a0e226e6fe9a \n", ".. ... \n", "415 68e0d79a3048252621b7d95c \n", "416 68e0d79a3048252621b7d95d \n", "417 68e0d79a3048252621b7d95e \n", "418 68e0d79a3048252621b7d95f \n", "419 68e0d79a3048252621b7d960 \n", "\n", " key \n", "0 Versatile homogeneous interface Jaclynborough ... \n", "1 Intuitive empowering orchestration New Mariabe... \n", "2 Reduced content-based product Port Alexis Ston... \n", "3 Object-based intermediate artificial intellige... \n", "4 Grass-roots global hub New Chrisport Fletcher-... \n", ".. ... \n", "415 Extended full-range open system New Carrie Whi... \n", "416 Polarized discrete benchmark Lake Stacyport Mo... \n", "417 Proactive reciprocal challenge Walkerview Scot... \n", "418 Grass-roots secondary forecast Andrewberg More... \n", "419 Integrated actuating infrastructure New Erica ... \n", "\n", "[420 rows x 2 columns]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "events" ] }, { "cell_type": "code", "execution_count": 15, "id": "c0bcdadf", "metadata": {}, "outputs": [], "source": [ "#lowercase and remove punctuation\n", "events['key'] = events['key'].str.lower()\n", "events['key'] = events['key'].str.translate(str.maketrans('', '', string.punctuation))" ] }, { "cell_type": "code", "execution_count": 16, "id": "d8711a8f", "metadata": {}, "outputs": [], "source": [ "cv = CountVectorizer(max_features=5000,stop_words='english')" ] }, { "cell_type": "code", "execution_count": 17, "id": "02acf870", "metadata": {}, "outputs": [], "source": [ "event_vector = cv.fit_transform(events['key']).toarray()" ] }, { "cell_type": "code", "execution_count": 18, "id": "e7de3754", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " ...,\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0],\n", " [0, 0, 0, ..., 0, 0, 0]])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "event_vector" ] }, { "cell_type": "code", "execution_count": 19, "id": "c8803cbf", "metadata": {}, "outputs": [], "source": [ "event_similarity = cosine_similarity(event_vector)" ] }, { "cell_type": "code", "execution_count": 20, "id": "4d2ee26c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(0, np.float64(1.0)),\n", " (1, np.float64(0.0)),\n", " (2, np.float64(0.04761904761904762)),\n", " (3, np.float64(0.03688555567816587)),\n", " (4, np.float64(0.0)),\n", " (5, np.float64(0.07715167498104596)),\n", " (6, np.float64(0.09100315103865803)),\n", " (7, np.float64(0.18200630207731605)),\n", " (8, np.float64(0.0)),\n", " (9, np.float64(0.0)),\n", " (10, np.float64(0.043643578047198484)),\n", " (11, np.float64(0.15877683720748895)),\n", " (12, np.float64(0.09304842103984708)),\n", " (13, np.float64(0.05006261743217588)),\n", " (14, np.float64(0.0)),\n", " (15, np.float64(0.09523809523809525)),\n", " (16, np.float64(0.04550157551932901)),\n", " (17, np.float64(0.12598815766974242)),\n", " (18, np.float64(0.0)),\n", " (19, np.float64(0.0)),\n", " (20, np.float64(0.08728715609439697)),\n", " (21, np.float64(0.05006261743217588)),\n", " (22, np.float64(0.0545544725589981)),\n", " (23, np.float64(0.0)),\n", " (24, np.float64(0.03919309008348103)),\n", " (25, np.float64(0.0)),\n", " (26, np.float64(0.1283881477532739)),\n", " (27, np.float64(0.10286889997472795)),\n", " (28, np.float64(0.0)),\n", " (29, np.float64(0.14638501094227999)),\n", " (30, np.float64(0.13363062095621223)),\n", " (31, np.float64(0.044543540318737404)),\n", " (32, np.float64(0.044543540318737404)),\n", " (33, np.float64(0.1567723603339241)),\n", " (34, np.float64(0.12598815766974242)),\n", " (35, np.float64(0.0563436169819011)),\n", " (36, np.float64(0.043643578047198484)),\n", " (37, np.float64(0.09523809523809525)),\n", " (38, np.float64(0.13957263155977062)),\n", " (39, np.float64(0.0)),\n", " (40, np.float64(0.15936381457791915)),\n", " (41, np.float64(0.08728715609439697)),\n", " (42, np.float64(0.08104408984731078)),\n", " (43, np.float64(0.0)),\n", " (44, np.float64(0.04550157551932901)),\n", " (45, np.float64(0.0)),\n", " (46, np.float64(0.0)),\n", " (47, np.float64(0.0)),\n", " (48, np.float64(0.05006261743217588)),\n", " (49, np.float64(0.042796049251091296)),\n", " (50, np.float64(0.04550157551932901)),\n", " (51, np.float64(0.0)),\n", " (52, np.float64(0.09100315103865803)),\n", " (53, np.float64(0.0)),\n", " (54, np.float64(0.0)),\n", " (55, np.float64(0.08728715609439697)),\n", " (56, np.float64(0.0)),\n", " (57, np.float64(0.07715167498104596)),\n", " (58, np.float64(0.043643578047198484)),\n", " (59, np.float64(0.04652421051992354)),\n", " (60, np.float64(0.044543540318737404)),\n", " (61, np.float64(0.0)),\n", " (62, np.float64(0.03587480016670876)),\n", " (63, np.float64(0.043643578047198484)),\n", " (64, np.float64(0.13957263155977062)),\n", " (65, np.float64(0.0)),\n", " (66, np.float64(0.0)),\n", " (67, np.float64(0.11757927025044308)),\n", " (68, np.float64(0.04761904761904762)),\n", " (69, np.float64(0.051434449987363975)),\n", " (70, np.float64(0.0)),\n", " (71, np.float64(0.0563436169819011)),\n", " (72, np.float64(0.0)),\n", " (73, np.float64(0.04652421051992354)),\n", " (74, np.float64(0.0)),\n", " (75, np.float64(0.09523809523809525)),\n", " (76, np.float64(0.08399210511316162)),\n", " (77, np.float64(0.0)),\n", " (78, np.float64(0.04879500364742666)),\n", " (79, np.float64(0.13957263155977062)),\n", " (80, np.float64(0.0)),\n", " (81, np.float64(0.05006261743217588)),\n", " (82, np.float64(0.04652421051992354)),\n", " (83, np.float64(0.09304842103984708)),\n", " (84, np.float64(0.0)),\n", " (85, np.float64(0.08247860988423225)),\n", " (86, np.float64(0.12371791482634838)),\n", " (87, np.float64(0.0)),\n", " (88, np.float64(0.07597371763975865)),\n", " (89, np.float64(0.04052204492365539)),\n", " (90, np.float64(0.043643578047198484)),\n", " (91, np.float64(0.041239304942116126)),\n", " (92, np.float64(0.0)),\n", " (93, np.float64(0.0)),\n", " (94, np.float64(0.04879500364742666)),\n", " (95, np.float64(0.0)),\n", " (96, np.float64(0.08247860988423225)),\n", " (97, np.float64(0.16208817969462155)),\n", " (98, np.float64(0.0)),\n", " (99, np.float64(0.044543540318737404)),\n", " (100, np.float64(0.0)),\n", " (101, np.float64(0.0)),\n", " (102, np.float64(0.1904761904761905)),\n", " (103, np.float64(0.03984095364447979)),\n", " (104, np.float64(0.08728715609439697)),\n", " (105, np.float64(0.043643578047198484)),\n", " (106, np.float64(0.0)),\n", " (107, np.float64(0.09759000729485331)),\n", " (108, np.float64(0.04761904761904762)),\n", " (109, np.float64(0.04652421051992354)),\n", " (110, np.float64(0.0)),\n", " (111, np.float64(0.0)),\n", " (112, np.float64(0.0)),\n", " (113, np.float64(0.23145502494313788)),\n", " (114, np.float64(0.09523809523809525)),\n", " (115, np.float64(0.0)),\n", " (116, np.float64(0.12156613477096617)),\n", " (117, np.float64(0.04879500364742666)),\n", " (118, np.float64(0.0)),\n", " (119, np.float64(0.03857583749052298)),\n", " (120, np.float64(0.04550157551932901)),\n", " (121, np.float64(0.0)),\n", " (122, np.float64(0.044543540318737404)),\n", " (123, np.float64(0.044543540318737404)),\n", " (124, np.float64(0.041239304942116126)),\n", " (125, np.float64(0.04199605255658081)),\n", " (126, np.float64(0.08559209850218259)),\n", " (127, np.float64(0.0)),\n", " (128, np.float64(0.0)),\n", " (129, np.float64(0.044543540318737404)),\n", " (130, np.float64(0.0563436169819011)),\n", " (131, np.float64(0.14285714285714288)),\n", " (132, np.float64(0.0)),\n", " (133, np.float64(0.12598815766974242)),\n", " (134, np.float64(0.1091089451179962)),\n", " (135, np.float64(0.05292561240249632)),\n", " (136, np.float64(0.1283881477532739)),\n", " (137, np.float64(0.0)),\n", " (138, np.float64(0.04199605255658081)),\n", " (139, np.float64(0.09523809523809525)),\n", " (140, np.float64(0.04550157551932901)),\n", " (141, np.float64(0.0)),\n", " (142, np.float64(0.0)),\n", " (143, np.float64(0.043643578047198484)),\n", " (144, np.float64(0.042796049251091296)),\n", " (145, np.float64(0.08559209850218259)),\n", " (146, np.float64(0.18200630207731605)),\n", " (147, np.float64(0.04879500364742666)),\n", " (148, np.float64(0.044543540318737404)),\n", " (149, np.float64(0.04652421051992354)),\n", " (150, np.float64(0.0)),\n", " (151, np.float64(0.0)),\n", " (152, np.float64(0.04652421051992354)),\n", " (153, np.float64(0.05292561240249632)),\n", " (154, np.float64(0.09759000729485331)),\n", " (155, np.float64(0.13650472655798704)),\n", " (156, np.float64(0.04550157551932901)),\n", " (157, np.float64(0.07597371763975865)),\n", " (158, np.float64(0.0)),\n", " (159, np.float64(0.0)),\n", " (160, np.float64(0.044543540318737404)),\n", " (161, np.float64(0.07597371763975865)),\n", " (162, np.float64(0.0)),\n", " (163, np.float64(0.08104408984731078)),\n", " (164, np.float64(0.05292561240249632)),\n", " (165, np.float64(0.09759000729485331)),\n", " (166, np.float64(0.10286889997472795)),\n", " (167, np.float64(0.04652421051992354)),\n", " (168, np.float64(0.0545544725589981)),\n", " (169, np.float64(0.14638501094227999)),\n", " (170, np.float64(0.08559209850218259)),\n", " (171, np.float64(0.0545544725589981)),\n", " (172, np.float64(0.044543540318737404)),\n", " (173, np.float64(0.0)),\n", " (174, np.float64(0.0)),\n", " (175, np.float64(0.0545544725589981)),\n", " (176, np.float64(0.13363062095621223)),\n", " (177, np.float64(0.08399210511316162)),\n", " (178, np.float64(0.09304842103984708)),\n", " (179, np.float64(0.04550157551932901)),\n", " (180, np.float64(0.09523809523809525)),\n", " (181, np.float64(0.07838618016696206)),\n", " (182, np.float64(0.04550157551932901)),\n", " (183, np.float64(0.04652421051992354)),\n", " (184, np.float64(0.0)),\n", " (185, np.float64(0.14638501094227999)),\n", " (186, np.float64(0.10012523486435176)),\n", " (187, np.float64(0.04199605255658081)),\n", " (188, np.float64(0.09759000729485331)),\n", " (189, np.float64(0.04550157551932901)),\n", " (190, np.float64(0.04761904761904762)),\n", " (191, np.float64(0.043643578047198484)),\n", " (192, np.float64(0.0)),\n", " (193, np.float64(0.0)),\n", " (194, np.float64(0.08908708063747481)),\n", " (195, np.float64(0.08247860988423225)),\n", " (196, np.float64(0.0545544725589981)),\n", " (197, np.float64(0.0)),\n", " (198, np.float64(0.0)),\n", " (199, np.float64(0.1091089451179962)),\n", " (200, np.float64(0.15018785229652765)),\n", " (201, np.float64(0.16208817969462155)),\n", " (202, np.float64(0.05006261743217588)),\n", " (203, np.float64(0.11952286093343936)),\n", " (204, np.float64(0.1543033499620919)),\n", " (205, np.float64(0.0)),\n", " (206, np.float64(0.04879500364742666)),\n", " (207, np.float64(0.0)),\n", " (208, np.float64(0.14285714285714288)),\n", " (209, np.float64(0.0)),\n", " (210, np.float64(0.058321184351980436)),\n", " (211, np.float64(0.0)),\n", " (212, np.float64(0.10012523486435176)),\n", " (213, np.float64(0.0)),\n", " (214, np.float64(0.10585122480499264)),\n", " (215, np.float64(0.0)),\n", " (216, np.float64(0.0)),\n", " (217, np.float64(0.08104408984731078)),\n", " (218, np.float64(0.042796049251091296)),\n", " (219, np.float64(0.03857583749052298)),\n", " (220, np.float64(0.11227217828476795)),\n", " (221, np.float64(0.13957263155977062)),\n", " (222, np.float64(0.0)),\n", " (223, np.float64(0.07715167498104596)),\n", " (224, np.float64(0.15430334996209194)),\n", " (225, np.float64(0.0)),\n", " (226, np.float64(0.042796049251091296)),\n", " (227, np.float64(0.0)),\n", " (228, np.float64(0.03742405942825598)),\n", " (229, np.float64(0.0)),\n", " (230, np.float64(0.07715167498104596)),\n", " (231, np.float64(0.041239304942116126)),\n", " (232, np.float64(0.0)),\n", " (233, np.float64(0.14638501094227999)),\n", " (234, np.float64(0.10012523486435176)),\n", " (235, np.float64(0.04879500364742666)),\n", " (236, np.float64(0.12598815766974242)),\n", " (237, np.float64(0.08399210511316162)),\n", " (238, np.float64(0.0)),\n", " (239, np.float64(0.0)),\n", " (240, np.float64(0.09759000729485331)),\n", " (241, np.float64(0.03742405942825598)),\n", " (242, np.float64(0.0563436169819011)),\n", " (243, np.float64(0.051434449987363975)),\n", " (244, np.float64(0.04652421051992354)),\n", " (245, np.float64(0.0)),\n", " (246, np.float64(0.0)),\n", " (247, np.float64(0.04550157551932901)),\n", " (248, np.float64(0.0)),\n", " (249, np.float64(0.0)),\n", " (250, np.float64(0.0)),\n", " (251, np.float64(0.12598815766974242)),\n", " (252, np.float64(0.10012523486435176)),\n", " (253, np.float64(0.0)),\n", " (254, np.float64(0.08908708063747481)),\n", " (255, np.float64(0.0)),\n", " (256, np.float64(0.0)),\n", " (257, np.float64(0.042796049251091296)),\n", " (258, np.float64(0.0)),\n", " (259, np.float64(0.0)),\n", " (260, np.float64(0.03919309008348103)),\n", " (261, np.float64(0.042796049251091296)),\n", " (262, np.float64(0.21398024625545647)),\n", " (263, np.float64(0.0)),\n", " (264, np.float64(0.11952286093343936)),\n", " (265, np.float64(0.04652421051992354)),\n", " (266, np.float64(0.08728715609439697)),\n", " (267, np.float64(0.043643578047198484)),\n", " (268, np.float64(0.042796049251091296)),\n", " (269, np.float64(0.0)),\n", " (270, np.float64(0.0)),\n", " (271, np.float64(0.04652421051992354)),\n", " (272, np.float64(0.0)),\n", " (273, np.float64(0.0)),\n", " (274, np.float64(0.0)),\n", " (275, np.float64(0.09759000729485331)),\n", " (276, np.float64(0.0)),\n", " (277, np.float64(0.14285714285714288)),\n", " (278, np.float64(0.06900655593423542)),\n", " (279, np.float64(0.041239304942116126)),\n", " (280, np.float64(0.03919309008348103)),\n", " (281, np.float64(0.058321184351980436)),\n", " (282, np.float64(0.09304842103984708)),\n", " (283, np.float64(0.0)),\n", " (284, np.float64(0.0)),\n", " (285, np.float64(0.04550157551932901)),\n", " (286, np.float64(0.1283881477532739)),\n", " (287, np.float64(0.058321184351980436)),\n", " (288, np.float64(0.04761904761904762)),\n", " (289, np.float64(0.0)),\n", " (290, np.float64(0.08247860988423225)),\n", " (291, np.float64(0.09304842103984708)),\n", " (292, np.float64(0.04550157551932901)),\n", " (293, np.float64(0.09100315103865803)),\n", " (294, np.float64(0.0)),\n", " (295, np.float64(0.0)),\n", " (296, np.float64(0.043643578047198484)),\n", " (297, np.float64(0.05006261743217588)),\n", " (298, np.float64(0.07273929674533079)),\n", " (299, np.float64(0.043643578047198484)),\n", " (300, np.float64(0.0)),\n", " (301, np.float64(0.04761904761904762)),\n", " (302, np.float64(0.0)),\n", " (303, np.float64(0.03742405942825598)),\n", " (304, np.float64(0.0)),\n", " (305, np.float64(0.0)),\n", " (306, np.float64(0.04550157551932901)),\n", " (307, np.float64(0.09304842103984708)),\n", " (308, np.float64(0.03984095364447979)),\n", " (309, np.float64(0.07968190728895957)),\n", " (310, np.float64(0.05006261743217588)),\n", " (311, np.float64(0.1091089451179962)),\n", " (312, np.float64(0.08247860988423225)),\n", " (313, np.float64(0.0)),\n", " (314, np.float64(0.08728715609439697)),\n", " (315, np.float64(0.05292561240249632)),\n", " (316, np.float64(0.0)),\n", " (317, np.float64(0.04761904761904762)),\n", " (318, np.float64(0.0)),\n", " (319, np.float64(0.08728715609439697)),\n", " (320, np.float64(0.0)),\n", " (321, np.float64(0.0)),\n", " (322, np.float64(0.042796049251091296)),\n", " (323, np.float64(0.15430334996209194)),\n", " (324, np.float64(0.1283881477532739)),\n", " (325, np.float64(0.09100315103865803)),\n", " (326, np.float64(0.12371791482634838)),\n", " (327, np.float64(0.18200630207731605)),\n", " (328, np.float64(0.043643578047198484)),\n", " (329, np.float64(0.18609684207969415)),\n", " (330, np.float64(0.1283881477532739)),\n", " (331, np.float64(0.08728715609439697)),\n", " (332, np.float64(0.08559209850218259)),\n", " (333, np.float64(0.07715167498104596)),\n", " (334, np.float64(0.04879500364742666)),\n", " (335, np.float64(0.0)),\n", " (336, np.float64(0.20025046972870353)),\n", " (337, np.float64(0.17118419700436519)),\n", " (338, np.float64(0.0)),\n", " (339, np.float64(0.04052204492365539)),\n", " (340, np.float64(0.0)),\n", " (341, np.float64(0.051434449987363975)),\n", " (342, np.float64(0.05292561240249632)),\n", " (343, np.float64(0.0)),\n", " (344, np.float64(0.0)),\n", " (345, np.float64(0.0)),\n", " (346, np.float64(0.044543540318737404)),\n", " (347, np.float64(0.11396057645963796)),\n", " (348, np.float64(0.15018785229652765)),\n", " (349, np.float64(0.060522753266880246)),\n", " (350, np.float64(0.0)),\n", " (351, np.float64(0.08399210511316162)),\n", " (352, np.float64(0.09523809523809525)),\n", " (353, np.float64(0.0)),\n", " (354, np.float64(0.0)),\n", " (355, np.float64(0.09304842103984708)),\n", " (356, np.float64(0.09304842103984708)),\n", " (357, np.float64(0.04761904761904762)),\n", " (358, np.float64(0.0)),\n", " (359, np.float64(0.08559209850218259)),\n", " (360, np.float64(0.04550157551932901)),\n", " (361, np.float64(0.0)),\n", " (362, np.float64(0.0)),\n", " (363, np.float64(0.0)),\n", " (364, np.float64(0.0)),\n", " (365, np.float64(0.09304842103984708)),\n", " (366, np.float64(0.043643578047198484)),\n", " (367, np.float64(0.0)),\n", " (368, np.float64(0.0)),\n", " (369, np.float64(0.0)),\n", " (370, np.float64(0.0)),\n", " (371, np.float64(0.0)),\n", " (372, np.float64(0.0)),\n", " (373, np.float64(0.04879500364742666)),\n", " (374, np.float64(0.08908708063747481)),\n", " (375, np.float64(0.0)),\n", " (376, np.float64(0.04199605255658081)),\n", " (377, np.float64(0.0)),\n", " (378, np.float64(0.09304842103984708)),\n", " (379, np.float64(0.13363062095621223)),\n", " (380, np.float64(0.05006261743217588)),\n", " (381, np.float64(0.1315903389919538)),\n", " (382, np.float64(0.043643578047198484)),\n", " (383, np.float64(0.04199605255658081)),\n", " (384, np.float64(0.03919309008348103)),\n", " (385, np.float64(0.10585122480499264)),\n", " (386, np.float64(0.09100315103865803)),\n", " (387, np.float64(0.14285714285714288)),\n", " (388, np.float64(0.044543540318737404)),\n", " (389, np.float64(0.0)),\n", " (390, np.float64(0.043643578047198484)),\n", " (391, np.float64(0.03984095364447979)),\n", " (392, np.float64(0.09304842103984708)),\n", " (393, np.float64(0.043643578047198484)),\n", " (394, np.float64(0.0)),\n", " (395, np.float64(0.051434449987363975)),\n", " (396, np.float64(0.04761904761904762)),\n", " (397, np.float64(0.08908708063747481)),\n", " (398, np.float64(0.14285714285714288)),\n", " (399, np.float64(0.0)),\n", " (400, np.float64(0.0)),\n", " (401, np.float64(0.13650472655798704)),\n", " (402, np.float64(0.14638501094227999)),\n", " (403, np.float64(0.04199605255658081)),\n", " (404, np.float64(0.0)),\n", " (405, np.float64(0.07838618016696206)),\n", " (406, np.float64(0.08728715609439697)),\n", " (407, np.float64(0.04199605255658081)),\n", " (408, np.float64(0.044543540318737404)),\n", " (409, np.float64(0.09523809523809525)),\n", " (410, np.float64(0.07838618016696206)),\n", " (411, np.float64(0.0)),\n", " (412, np.float64(0.051434449987363975)),\n", " (413, np.float64(0.09100315103865803)),\n", " (414, np.float64(0.0)),\n", " (415, np.float64(0.05006261743217588)),\n", " (416, np.float64(0.041239304942116126)),\n", " (417, np.float64(0.09523809523809525)),\n", " (418, np.float64(0.0)),\n", " (419, np.float64(0.0))]" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(enumerate(event_similarity[0]))" ] }, { "cell_type": "code", "execution_count": 21, "id": "05b74faf", "metadata": {}, "outputs": [], "source": [ "def recommend_event(event_id):\n", " matches = events[events['event_id'] == event_id]\n", " if matches.empty:\n", " print(f\"Event ID {event_id} not found.\")\n", " return\n", " index = matches.index[0]\n", " distances = event_similarity[index]\n", " events_list = sorted(list(enumerate(distances)), reverse=True, key=lambda x: x[1])[1:6]\n", " for i in events_list:\n", " print(events.iloc[i[0]].event_id)\n", " return" ] }, { "cell_type": "code", "execution_count": 22, "id": "8f643bcb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "68e0d7821f7dc4e22f39d565\n", "68e0d79a3048252621b7d8c3\n", "68e0d79a3048252621b7d90d\n", "68e0d7821f7dc4e22f39d55a\n", "68e0d79a3048252621b7d906\n" ] } ], "source": [ "recommend_event('68e0d68abee8a0e226e6fe96')" ] }, { "cell_type": "code", "execution_count": 23, "id": "ed2dfafa", "metadata": {}, "outputs": [], "source": [ "import os\n", "import pickle\n", "os.makedirs('../model', exist_ok=True)\n", "pickle.dump(event_similarity, open('../model/events_similarity.pkl', 'wb'))" ] }, { "cell_type": "code", "execution_count": 24, "id": "1df95655", "metadata": {}, "outputs": [], "source": [ "pickle.dump(events, open('../model/events.pkl', 'wb'))" ] }, { "cell_type": "code", "execution_count": 25, "id": "059ac981", "metadata": {}, "outputs": [], "source": [ "pickle.dump(event_vector, open('../model/events_vector.pkl', 'wb'))" ] } ], "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.9.6" } }, "nbformat": 4, "nbformat_minor": 5 }