Recommendation Algorithm Case 1:
- 오석 양
- 2023년 8월 7일
- 4분 분량
최종 수정일: 2023년 8월 9일
An Application of the Hierarchical Ranking Theory between Preference and Distance for Tourism

Python Coding & Its Explanation
In this section, we will discuss the Python coding to implement a preference-distance based hierarchical application algorithm.
☞ Explanation
It appears that you have imported several Python libraries, including pandas, numpy, and selenium, as well as some specific modules from selenium like webdriver, Keys, WebDriverWait, expected_conditions, TimeoutException, NoSuchElementException, and Select. Additionally, you have imported the time module for handling time-related operations and the tqdm library for creating progress bars.
☞ Explanation
The given code uses the pandas library to read an Excel file and create a DataFrame. It then prints the DataFrame to display the data.
☞ Explanation
The provided code uses the sklearn library for text feature extraction and cosine similarity calculation. Specifically, it uses the CountVectorizer for vectorizing the text data and cosine_similarity for computing cosine similarity between vectors.
☞ Explanation
The provided code uses the sklearn library for text feature extraction and cosine similarity calculation with review text data.
☞ Explanation
The provided code is creating a formula to combine the importance of five different similarities (formular 1~5) into a single formula using weighted coefficients. The resulting formula place_simi_co combines category similarity (place_simi_cate), review text similarity (place_simi_review), the number of blog reviews (df['naver_blog_review_qty']), blog star rating (df['naver_star_point']), and the quantity of blog star ratings (df['naver_star_point_qty']) with different weighted coefficients.
In this code, place_simi_co is the combined similarity matrix obtained by applying the weights to each individual similarity matrix. place_simi_co_sorted_ind contains the sorted indices of the combined similarity matrix. The find_simi_place function takes the DataFrame df, the sorted indices sorted_ind, a place_name, and an optional top_n parameter, and returns the top N similar places based on the combined similarity matrix.
The function find_simi_place can be used to find similar places given a place name and specify the number of top similar places to retrieve. The returned DataFrame will contain the top N similar places ranked by their combined similarity values.
☞ Explanation
The haversine library is used to calculate the distance between two points on the Earth's surface. It is commonly used to compute the distance between two geographical coordinates specified by their latitude and longitude.
In the above code, we calculate the distance between Seoul and Tokyo using their respective latitude and longitude. The haversine function takes two tuples of latitude and longitude (in the format (latitude, longitude)) as input and returns the distance in kilometers.
The provided code appears to convert the latitude and longitude values in the DataFrame df from strings to float values. This conversion is likely done to ensure that the latitude and longitude values are in the correct numerical format for further calculations or processing, such as using the haversine library to compute distances.
☞ Explanation
The provided code creates a new column 'location' in the DataFrame df and populates it with tuples containing latitude and longitude values for each row. This approach allows you to manage the latitude and longitude of each location as a single tuple.
☞ Explanation
The provided code is an interactive Python script that takes user input to set a distance restriction for recommended tourist attractions. The code uses the input() function to collect the user's choice for the distance restriction and the mode of transportation. Based on the user's input, a specific distance value is set for the recommendation.
Based on the user's choice of transportation, the code sets the distance limit:
If the user chooses "1" for walking, the distance limit set_dist is set to 3 kilometers (30 minutes of walking).
If the user chooses "2" for cycling, the distance limit set_dist is set to 7 kilometers (30 minutes of cycling).
If the user chooses "3" for driving, the distance limit set_dist is set to 30 kilometers (30 minutes of driving).
The code allows users to interactively set a distance restriction for recommended tourist attractions based on their preferred mode of transportation.
☞ Explanation
The provided code iterates through the DataFrame df and prints the names of the places contained in the 'name' column. It displays the names of all the places present in the DataFrame.
☞ Explanation
By running this code, you can find other tourist spots in Chuncheon that are similar to the frequently visited tourist spot provided by the user. The results will be stored in the DataFrame simi_df, and you can explore the similar tourist spots by examining the content of simi_df.
☞ Explanation
The provided code is a loop that searches for a specific value in the 'name' column of the DataFrame df. It assigns the index of the row where the value is found to the variable rec.
☞ Explanation
The provided code calculates the distances between the location of the frequently visited tourist spot (cafe_name) and the locations of other similar tourist spots found in the simi_df DataFrame. It uses the haversine function from the haversine library to compute the distances based on latitude and longitude coordinates.
☞ Explanation
The provided code filters the simi_df DataFrame to create two new DataFrames: rec_df and final_rec_df. These new DataFrames contain rows that meet specific conditions related to the 'distance' column.
☞ Explanation
The provided code prints the names of the recommended tourist spots in final_rec_df DataFrame and displays the images of each spot. The images are expected to be stored in the "./chuncheontour/" folder with filenames corresponding to the names of the tourist spots. However, if the images are not available in the folder, it may raise an error.
Results of Processing Recommendation Algorithm
When the above series of coding is processed, the following result is presented:
봄내길 2코스(물깨말구구리길)

추곡약수터

청평사

천전리 지석묘군

의암호

지암계곡

집다리캠핑장

춘천 자전거길

죽림동성당

☞ Explanation
In this session, after receiving recommendations for tourist attractions in Chuncheon with the deep learning recommendation algorithm, ask chatGPT to recommend tourist attractions in Chuncheon and listen to the answers. If you go to your own chatGPT API and enter a question, ‘Can you recommend a tourist spot in Chuncheon?’, chatGPT will make a recommendation. However, chatGPT API requires a paid account.
As mentioned earlier, since chatGPT is a recommendation based on general information rather than personal preference, tourists themselves have to compare the Chuncheon tourist destinations recommended by the deep learning recommendation algorithm with the tourist attractions recommended by chatGPT and select the final destination to visit.
This time, we will write coding that requests chatGPT to provide detailed information about the tourist destinations recommended by the deep learning recommendation algorithm
☞ Explanation
This coding is designed to collect detailed information about the final tourist destination recommended by the deep learning recommendation algorithm and provide it to the tourist.
The End



댓글