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
y_final = (1*np.ravel(y_test_pred_xgb) + 1*np.ravel(y_test_pred_kridge) + 1*np.ravel(y_test_pred_lasso))/3 | |
y_final.shape | |
y_pred = np.exp(y_final) | |
# Final Conversion. | |
output_file = 'xgboost_lasso_kridge_weights_1_1_1' | |
final_file = '0108_'+ output_file +'.csv' | |
pred_df = pd.DataFrame(y_pred, index=test_df["Id"], columns=["SalePrice"]) |
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 xgboost import plot_importance | |
from matplotlib import pyplot | |
xgb_regr = xgb.XGBRegressor( | |
colsample_bytree=0.2, | |
gamma=0.0, | |
learning_rate=0.01, | |
max_depth=4, | |
min_child_weight=1.5, | |
n_estimators=7200, |
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
# 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)) |
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 = 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 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 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
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
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
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
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) |