Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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_id = pd.read_csv('links.csv', sep=',') | |
| idx_to_movie = {} | |
| for row in df_id.itertuples(): | |
| idx_to_movie[row[1]-1] = row[2] | |
| total_movies = 9000 | |
| movies = [0]*total_movies | |
| for i in range(len(movies)): |
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 requests | |
| import json | |
| from IPython.display import Image | |
| from IPython.display import display | |
| from IPython.display import HTML | |
| idx_to_movie = {} | |
| for row in df_id.itertuples(): | |
| idx_to_movie[row[1]-1] = row[2] |
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.metrics import mean_squared_error | |
| prediction = similarity_user.dot(train_matrix) / np.array([np.abs(similarity_user).sum(axis=1)]).T | |
| prediction = prediction[test_matrix.nonzero()].flatten() | |
| test_vector = test_matrix[test_matrix.nonzero()].flatten() | |
| mse = mean_squared_error(prediction, test_vector) | |
| print 'MSE = ' + str(mse) |
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
| similarity_user = train_matrix.dot(train_matrix.T) + 1e-9 | |
| norms = np.array([np.sqrt(np.diagonal(similarity_user))]) | |
| similarity_user = ( similarity_user / (norms * norms.T) ) | |
| similarity_movie = train_matrix.T.dot(train_matrix) + 1e-9 | |
| norms = np.array([np.sqrt(np.diagonal(similarity_movie))]) | |
| similarity_movie = ( similarity_movie / (norms * norms.T) ) |
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
| train_matrix = rating_matrix.copy() | |
| test_matrix = np.zeros(ratings_matrix.shape) | |
| for i in xrange(rating_matrix.shape[0]): | |
| rating_idx = np.random.choice( | |
| rating_matrix[i, :].nonzero()[0], | |
| size=10, | |
| replace=True) | |
| train_matrix[i, rating_idx] = 0.0 | |
| test_matrix[i, rating_idx] = rating_matrix[i, rating_idx] |
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
| sparsity = float(len(ratings.nonzero()[0])) | |
| sparsity /= (ratings.shape[0] * ratings.shape[1]) | |
| sparsity *= 100 |
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('ratings.csv', sep=',') | |
| df_id = pd.read_csv('links.csv', sep=',') | |
| df = pd.merge(df, df_id, on=['movieId']) | |
| rating_matrix = np.zeros((df.userId.unique().shape[0], max(df.movieId))) | |
| for row in df.itertuples(): | |
| rating_matrix[row[1]-1, row[2]-1] = row[3] | |
| rating_matrix = rating_matrix[:,:9000] |
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
| # Extra Trees Regressor | |
| et_regr = ExtraTreesRegressor() | |
| et_regr.fit(train_df_munged, label_df) | |
| # Run prediction on training set to get a rough idea of how well it does. | |
| y_pred = et_regr.predict(train_df_munged) | |
| y_test = label_df | |
| print("Extra Trees Regressor score on training set: ", rmse(y_test, y_pred)) |
NewerOlder