Kaggle competition: DS特論2019年度 演習課題2
df_dummy = pd.get_dummies(df_all['RoofMatl'],prefix='RoofMatl',dummy_na=True)
 df_all = pd.concat([df_all,df_dummy],axis=1)
 del df_all['RoofMatl']<data_type_conversions>
train_users_game1 = pd.read_csv('/kaggle/input/ds2019uec-task2/train_users_game1.csv')
 train_users_game2 = pd.read_csv('/kaggle/input/ds2019uec-task2/train_users_game2.csv')
 test_users_game1 = pd.read_csv('/kaggle/input/ds2019uec-task2/test_users_game1.csv')
 test_user_ids = pd.read_csv('/kaggle/input/ds2019uec-task2/test_user_ids.csv')
 game_group2 = pd.read_csv('/kaggle/input/ds2019uec-task2/game_group2.csv')
 sample_submission = pd.read_csv('/kaggle/input/ds2019uec-task2/sample_submission.csv' )
df_all['Exterior1st']= df_all['Exterior1st'].fillna('Other' )<categorify>
users_game1 = pd.concat([train_users_game1, test_users_game1] ).drop(['play_hour'], axis=1 ).drop_duplicates()
users_game1['label'] = 1
def Exterior1st(c):
if c == 'VinylSd':
return 1
elif c == 'Wd Sdng':
return 2
elif c == 'HdBoard':
return 3
elif c == 'Plywood':
return 4
elif c == 'MetalSd':
return 5
elif c == 'CemntBd':
return 6
elif c == 'WdShing':
return 7
elif c == 'BrkFace':
return 8
elif c == 'AsbShng':
return 9
else:
return 0<data_type_conversions>
user_ids = pd.concat([train_users_game1['user_id'], train_users_game2['user_id'], test_user_ids['user_id']] ).unique()
df_all['Exterior1st'] = df_all['Exterior1st'].apply(Exterior1st ).astype(int )<categorify>
users_game1_matrix = users_game1.set_index(['user_id', 'game_title'])['label'].unstack().reindex(user_ids ).fillna(0 )
def BsmtFinSF1(n):
if(n > -1)&(n <= 150):
return 1
elif(n > 150)&(n <= 300):
return 2
elif(n > 300)&(n <= 450):
return 3
elif(n > 450)&(n <= 600):
return 4
elif(n > 600)&(n <= 750):
return 5
else:
return 10<data_type_conversions>
train_user_ids = pd.concat([train_users_game1['user_id'], train_users_game2['user_id']] ).unique()
test_user_ids = test_user_ids['user_id'].values
df_all['BsmtFinSF1'] = df_all['BsmtFinSF1'].apply(BsmtFinSF1 ).astype(int )<concatenate>
users_similarity = 1 - cosine_distances(users_game1_matrix.loc[test_user_ids], users_game1_matrix.loc[train_user_ids] )
def MasVnrArea(n):
if(n > -1)&(n <= 150):
return 1
elif(n > 150)&(n <= 200):
return 2
elif(n > 200)&(n <= 300):
return 3
else:
return 0<data_type_conversions>
users_game2 = train_users_game2.drop(['play_hour', 'predict_game_id'], axis=1 ).drop_duplicates()
users_game2['label'] = 1
df_all['MasVnrArea'] = df_all['MasVnrArea'].apply(MasVnrArea ).astype(int )<categorify>
test_users_game2_matrix =(users_similarity @ users_game2_matrix.loc[train_user_ids] )
df_dummy = pd.get_dummies(df_all['ExterQual'],prefix='ExterQual',dummy_na=True)
 df_all = pd.concat([df_all,df_dummy],axis=1)
 del df_all['ExterQual']<categorify>
sample_submission['purchased_games'] = test_users_game2_matrix.apply(lambda x: ' '.join(x.sort_values(ascending=False)[:10].index.astype('str')) , axis=1 )
df_dummy = pd.get_dummies(df_all['ExterCond'],prefix='ExterCond',dummy_na=True)
 df_all = pd.concat([df_all,df_dummy],axis=1)
 del df_all['ExterCond']<categorify>
sample_submission.loc[test_users_game2_matrix.sum(axis=1)== 0, 'purchased_games'] = ' '.join(train_users_game2['predict_game_id'].value_counts(normalize=True ).index.astype('str')[:10] )
df_all['BsmtQual'] = df_all['BsmtQual'].fillna('TA')
 df_dummy = pd.get_dummies(df_all['BsmtQual'],prefix='BsmtQual',dummy_na=True)
 df_all = pd.concat([df_all,df_dummy],axis=1)
 del df_all['BsmtQual']<categorify>
sample_submission.to_csv('submission.csv', index=None )