This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
recommend('Hampton Inn Suites National HarborAlexandria Area') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
recommend('Silver Sands Oceanfront Motel') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
recommend('AC Hotel Miami Beach') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recommend(hotel_name): | |
# get index of hotel in ratings matrix | |
index = ratings_matrix.columns.get_loc(hotel_name) | |
# person coefficients of the hotel | |
hotel_coeff = pearson_matrix[index] | |
# create dataframe and sort by coeff and get top 10 | |
return pd.DataFrame({'pearson':hotel_coeff, 'hotel': ratings_matrix.columns}).sort_values('pearson', ascending=False).head(1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pearson_matrix = np.corrcoef(ratings_svd) | |
pearson_matrix.shape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.decomposition import TruncatedSVD | |
SVD = TruncatedSVD(n_components=10, random_state=34) | |
ratings_svd = SVD.fit_transform(ratings_transpose) | |
ratings_svd.shape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import sklearn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ratings_transpose = ratings_matrix.T | |
ratings_transpose.head(5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ratings_matrix = ratings.pivot_table(values='rating', index='user', columns='hotel', fill_value=0) | |
ratings_matrix.head(5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = pd.read_csv('hotel_reviews.csv') | |
df.head() | |
ratings = df[['reviews.username','name','reviews.rating']] | |
ratings = ratings.drop_duplicates() | |
ratings.columns = ["user","hotel","rating"] | |
#8866 unique ratings | |
ratings.head(5) |
NewerOlder