This file contains 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
# creating matrices for sklearn: | |
x_train = np.array(train_df_munged) | |
x_test = np.array(test_df_munged) | |
y_train = label_df.values | |
ntrain = x_train.shape[0] | |
ntest = x_test.shape[0] | |
kf = KFold(ntrain, n_folds=NFOLDS, shuffle=True, random_state=SEED) |
This file contains 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) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
quality_dict = {None: 0, "Po": 1, "Fa": 2, "TA": 3, "Gd": 4, "Ex": 5} | |
train_df["ExterQual"] = df["ExterQual"].map(quality_dict).astype(int) | |
train_df["ExterCond"] = df["ExterCond"].map(quality_dict).astype(int) | |
train_df["BsmtQual"] = df["BsmtQual"].map(quality_dict).astype(int) | |
train_df["BsmtCond"] = df["BsmtCond"].map(quality_dict).astype(int) | |
train_df["HeatingQC"] = df["HeatingQC"].map(quality_dict).astype(int) | |
train_df["KitchenQual"] = df["KitchenQual"].map(quality_dict).astype(int) | |
train_df["FireplaceQu"] = df["FireplaceQu"].map(quality_dict).astype(int) | |
train_df["GarageQual"] = df["GarageQual"].map(quality_dict).astype(int) |
This file contains 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 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 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 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 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] |
NewerOlder