Untuk membangun sistem rekomendasi restoran menggunakan Python, saya telah mengumpulkan data dari Kaggle. Teman-teman dapat mengunduh dataset dalam format `.*csv` untuk tugas ini di sini.
Setelah mengunduh `TripAdvisor_RestauarantRecommendation.csv`, sekarang mari impor library Python yang diperlukan dan dataset yang kita butuhkan untuk permainan duniawi ini:
import numpy as np
import pandas as pd
from sklearn.feature_extraction import text
from sklearn.metrics.pairwise import cosine_similarity
data = pd.read_csv("TripAdvisor_RestauarantRecommendation.csv")
print(data.head())
data = data[["Name", "Type"]]
print(data.head())
print(data.isnull().sum())
data = data.dropna()
feature = data["Type"].tolist()
tfidf = text.TfidfVectorizer(input=feature, stop_words="english")
tfidf_matrix = tfidf.fit_transform(feature)
similarity = cosine_similarity(tfidf_matrix)
indices = pd.Series(data.index, index=data['Name']).drop_duplicates()
def restaurant_recommendation(name, similarity = similarity):
index = indices[name]
similarity_scores = list(enumerate(similarity[index]))
similarity_scores = sorted(similarity_scores, key=lambda x: x[1], reverse=True)
similarity_scores = similarity_scores[0:10]
restaurantindices = [i[0] for i in similarity_scores]
return data['Name'].iloc[restaurantindices]
print(restaurant_recommendation("Market Grill"))