<jupyter_start><jupyter_text>Delete column<jupyter_code>del df["Upc"]
del df["FinelineNumber"]<jupyter_output><empty_output><jupyter_text>Get dummy<jupyter_code>weekday = pd.get_dummies(df['Weekday'])
weekday = weekday.sort_index()
weekday
DepartmentDescription = pd.get_dummies(df['DepartmentDescription'])
DepartmentDescription = DepartmentDescription.sort_index()
DepartmentDescription
del df["Weekday"]
del df["DepartmentDescription"]
df = pd.concat([df, weekday, DepartmentDescription],axis=1)
df<jupyter_output><empty_output><jupyter_text>Make a data<jupyter_code>gdf1 = df[['TripType', "VisitNumber", "Friday", "Monday", "Saturday", "Thursday", "Tuesday", "Wednesday"]].groupby("VisitNumber").mean()
gdf2 = df[['VisitNumber', 'ScanCount', 'SHOES', 'DAIRY', 'GROCERY DRY GOODS', 'DSD GROCERY', 'BAKERY',
       'IMPULSE MERCHANDISE', 'PERSONAL CARE', 'FABRICS AND CRAFTS',
       'BOYS WEAR', 'PRE PACKED DELI', 'MENS WEAR', 'CELEBRATION',
       'HOUSEHOLD CHEMICALS/SUPP', 'FROZEN FOODS', 'PRODUCE',
       'HOME MANAGEMENT', 'PHARMACY OTC', 'CANDY, TOBACCO, COOKIES',
       'HOUSEHOLD PAPER GOODS', 'SPORTING GOODS', 'HARDWARE',
       'COMM BREAD', 'HOME DECOR', 'COOK AND DINE', 'SERVICE DELI',
       'PETS AND SUPPLIES', 'MEAT - FRESH & FROZEN', 'FINANCIAL SERVICES',
       'SEAFOOD', 'WIRELESS', 'MEDIA AND GAMING', 'PAINT AND ACCESSORIES',
       'LADIESWEAR', 'SLEEPWEAR/FOUNDATIONS', 'BEAUTY',
       'BRAS & SHAPEWEAR', 'FURNITURE', 'LAWN AND GARDEN', 'AUTOMOTIVE',
       'BATH AND SHOWER', 'ELECTRONICS', 'OFFICE SUPPLIES',
       'INFANT CONSUMABLE HARDLINES', 'GIRLS WEAR, 4-6X  AND 7-14',
       'INFANT APPAREL', 'LIQUOR,WINE,BEER', 'BOOKS AND MAGAZINES',
       'HORTICULTURE AND ACCESS', 'JEWELRY AND SUNGLASSES', 'ACCESSORIES',
       'LADIES SOCKS', 'BEDDING', 'TOYS', 'OPTICAL - FRAMES',
       'PHARMACY RX', 'CAMERAS AND SUPPLIES', 'MENSWEAR',
       'PLAYERS AND ELECTRONICS', 'PLUS AND MATERNITY',
       'SWIMWEAR/OUTERWEAR', 'CONCEPT STORES', 'SHEER HOSIERY',
       'LARGE HOUSEHOLD GOODS', 'OPTICAL - LENSES', '1-HR PHOTO',
       'OTHER DEPARTMENTS', 'SEASONAL']].groupby('VisitNumber').sum()
gdf = pd.concat([gdf1, gdf2], axis=1)
X = gdf.copy()
X.drop(columns = 'TripType', inplace=True)
X.tail()
y = gdf1['TripType'].copy()
y<jupyter_output><empty_output><jupyter_text>modeling<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)
import xgboost
model_xgb = xgboost.XGBClassifier(n_estimators=100, max_depth=11)
model_xgb.fit(X_train, y_train)
pred = model_xgb.predict(X_test)
pred
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
print(classification_report(y_test, pred))
# plot the important features #
fig, ax = plt.subplots(figsize=(12,25))
xgboost.plot_importance(model_xgb, ax=ax)
plt.show()
# test[test["DepartmentDescription"] == "HEALTH AND BEAUTY AIDS"]
train[train["DepartmentDescription"] == "HEALTH AND BEAUTY AIDS"]<jupyter_output><empty_output><jupyter_text>submission<jupyter_code>sub = test.copy()
del sub["Upc"]
del sub["FinelineNumber"]
test_weekday = pd.get_dummies(sub['Weekday'])
test_weekday = test_weekday.sort_index()
test_DepartmentDescription = pd.get_dummies(sub['DepartmentDescription'])
test_DepartmentDescription = test_DepartmentDescription.sort_index()
del sub["Weekday"]
del sub["DepartmentDescription"]
test_submission = pd.concat([sub, test_weekday, test_DepartmentDescription],axis=1)
test_submission
test_submission1 = test_submission[["VisitNumber", "Friday", "Monday", "Saturday", "Thursday", "Tuesday", "Wednesday"]].groupby("VisitNumber").mean()
test_submission1
test_submission2 = test_submission[['VisitNumber', 'ScanCount', 'SHOES', 'DAIRY', 'GROCERY DRY GOODS', 'DSD GROCERY', 'BAKERY',
       'IMPULSE MERCHANDISE', 'PERSONAL CARE', 'FABRICS AND CRAFTS',
       'BOYS WEAR', 'PRE PACKED DELI', 'MENS WEAR', 'CELEBRATION',
       'HOUSEHOLD CHEMICALS/SUPP', 'FROZEN FOODS', 'PRODUCE',
       'HOME MANAGEMENT', 'PHARMACY OTC', 'CANDY, TOBACCO, COOKIES',
       'HOUSEHOLD PAPER GOODS', 'SPORTING GOODS', 'HARDWARE',
       'COMM BREAD', 'HOME DECOR', 'COOK AND DINE', 'SERVICE DELI',
       'PETS AND SUPPLIES', 'MEAT - FRESH & FROZEN', 'FINANCIAL SERVICES',
       'SEAFOOD', 'WIRELESS', 'MEDIA AND GAMING', 'PAINT AND ACCESSORIES',
       'LADIESWEAR', 'SLEEPWEAR/FOUNDATIONS', 'BEAUTY',
       'BRAS & SHAPEWEAR', 'FURNITURE', 'LAWN AND GARDEN', 'AUTOMOTIVE',
       'BATH AND SHOWER', 'ELECTRONICS', 'OFFICE SUPPLIES',
       'INFANT CONSUMABLE HARDLINES', 'GIRLS WEAR, 4-6X  AND 7-14',
       'INFANT APPAREL', 'LIQUOR,WINE,BEER', 'BOOKS AND MAGAZINES',
       'HORTICULTURE AND ACCESS', 'JEWELRY AND SUNGLASSES', 'ACCESSORIES',
       'LADIES SOCKS', 'BEDDING', 'TOYS', 'OPTICAL - FRAMES',
       'PHARMACY RX', 'CAMERAS AND SUPPLIES', 'MENSWEAR',
       'PLAYERS AND ELECTRONICS', 'PLUS AND MATERNITY',
       'SWIMWEAR/OUTERWEAR', 'CONCEPT STORES', 'SHEER HOSIERY',
       'LARGE HOUSEHOLD GOODS', 'OPTICAL - LENSES', '1-HR PHOTO',
       'OTHER DEPARTMENTS', 'SEASONAL']].groupby('VisitNumber').sum()
test_submission2
testt = pd.concat([test_submission1, test_submission2], axis=1)
testt
sub_pred = model_xgb.predict(testt)
sub_pred
submi = pd.DataFrame(pd.get_dummies(sub_pred))
submi
submi.columns
a = pd.DataFrame(submi, columns=[  3,   4,   5,   6,   7,   8,   9,  12,  14,  15,  18,  19,  20,  21,
             22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,
             35,  36,  37,  38,  39,  40,  41,  42,  43,  44, 999])
a1 = a.fillna(0).astype(int)
VisitNumber = pd.DataFrame(testt.index)
my_submission = pd.concat([VisitNumber, a1], axis=1,)
my_submission.columns=['VisitNumber', 'TripType_3', 'TripType_4', 'TripType_5', 'TripType_6',
       'TripType_7', 'TripType_8', 'TripType_9', 'TripType_12', 'TripType_14',
       'TripType_15', 'TripType_18', 'TripType_19', 'TripType_20',
       'TripType_21', 'TripType_22', 'TripType_23', 'TripType_24',
       'TripType_25', 'TripType_26', 'TripType_27', 'TripType_28',
       'TripType_29', 'TripType_30', 'TripType_31', 'TripType_32',
       'TripType_33', 'TripType_34', 'TripType_35', 'TripType_36',
       'TripType_37', 'TripType_38', 'TripType_39', 'TripType_40',
       'TripType_41', 'TripType_42', 'TripType_43', 'TripType_44',
       'TripType_999']
my_submission
my_submission.to_csv("C:\\dss\\team_project2\\walmart\\my_submission",index=False)
sample_submission<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15571253071253072, 'fraction_numerical': 0.028101965601965602, 'mean_word_length': 5.250479846449136, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '12931', 'license': 'MIT', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2560, 'n_words': 511, 'path': 'First_modeling(Xgboost).ipynb', 'repo_name': 'tmdgms/Walmart-Recruiting-Trip-Type-Classification', 'size': '6512'}