[{'role': 'system', 'content': "You are an expert in machine learning and your task is to classify code snippets into one of the following categories: ['helper_functions', 'load_data', 'data_exploration', 'data_preprocessing', 'evaluation', 'modelling', 'prediction', 'result_visualization', 'save_results', 'comment_only']."}, {'role': 'user', 'content': 'Identify the single most appropriate category to which the provided code belongs. Provide your response as a single category label without any additional information, commentary, or personal opinions.\\nPython Code:__author__ = \'ZFTurbo: https://kaggle.com/zfturbo\'\n\nimport datetime\nimport pandas as pd\nimport numpy as np\nfrom sklearn.cross_validation import train_test_split\nimport xgboost as xgb\nimport random\nimport zipfile\nimport time\nimport shutil\nfrom sklearn.metrics import log_loss\n\nrandom.seed(2016)\n\ndef run_xgb(train, test, features, target, random_state=0):\n    eta = 0.3\n    max_depth = 6\n    subsample = 1\n    colsample_bytree = 0.7\n    start_time = time.time()\n\n    print(\'XGBoost params. ETA: {}, MAX_DEPTH: {}, SUBSAMPLE: {}, COLSAMPLE_BY_TREE: {}\'.format(eta, max_depth, subsample, colsample_bytree))\n    params = {\n        "objective": "multi:softprob",\n        "num_class": 12,\n        "booster" : "gbtree",\n        "eval_metric": "mlogloss",\n        "eta": eta,\n        "max_depth": max_depth,\n        "subsample": subsample,\n        "colsample_bytree": colsample_bytree,\n        "silent": 1,\n        "seed": random_state,\n    }\n    num_boost_round = 500\n    early_stopping_rounds = 50\n    test_size = 0.3\n\n    X_train, X_valid = train_test_split(train, test_size=test_size, random_state=random_state)\n    print(\'Length train:\', len(X_train.index))\n    print(\'Length valid:\', len(X_valid.index))\n    y_train = X_train[target]\n    y_valid = X_valid[target]\n    dtrain = xgb.DMatrix(X_train[features], y_train)\n    dvalid = xgb.DMatrix(X_valid[features], y_valid)\n\n    watchlist = [(dtrain, \'train\'), (dvalid, \'eval\')]\n    gbm = xgb.train(params, dtrain, num_boost_round, evals=watchlist, early_stopping_rounds=early_stopping_rounds, verbose_eval=True)\n\n    print("Validating...")\n    check = gbm.predict(xgb.DMatrix(X_valid[features]), ntree_limit=gbm.best_iteration)\n    score = log_loss(y_valid.tolist(), check)\n\n    print("Predict test set...")\n    test_prediction = gbm.predict(xgb.DMatrix(test[features]), ntree_limit=gbm.best_iteration)\n\n    print(\'Training time: {} minutes\'.format(round((time.time() - start_time)/60, 2)))\n    return test_prediction.tolist(), score\n\n\ndef create_submission(score, test, prediction):\n    # Make Submission\n    now = datetime.datetime.now()\n    sub_file = \'submission_\' + str(score) + \'_\' + str(now.strftime("%Y-%m-%d-%H-%M")) + \'.csv\'\n    print(\'Writing submission: \', sub_file)\n    f = open(sub_file, \'w\')\n    f.write(\'device_id,F23-,F24-26,F27-28,F29-32,F33-42,F43+,M22-,M23-26,M27-28,M29-31,M32-38,M39+\\\n\')\n    total = 0\n    test_val = test[\'device_id\'].values\n    for i in range(len(test_val)):\n        str1 = str(test_val[i])\n        for j in range(12):\n            str1 += \',\' + str(prediction[i][j])\n        str1 += \'\\\n\'\n        total += 1\n        f.write(str1)\n    f.close()\n\n\ndef map_column(table, f):\n    labels = sorted(table[f].unique())\n    mappings = dict()\n    for i in range(len(labels)):\n        mappings[labels[i]] = i\n    table = table.replace({f: mappings})\n    return table\n\n\ndef read_train_test():\n    # Events\n    print(\'Read events...\')\n    events = pd.read_csv("../input/events.csv", dtype={\'device_id\': np.str})\n    events[\'counts\'] = events.groupby([\'device_id\'])[\'event_id\'].transform(\'count\')\n    events_small = events[[\'device_id\', \'counts\']].drop_duplicates(\'device_id\', keep=\'first\')\n\n    # Phone brand\n    print(\'Read brands...\')\n    pbd = pd.read_csv("../input/phone_brand_device_model.csv", dtype={\'device_id\': np.str})\n    pbd.drop_duplicates(\'device_id\', keep=\'first\', inplace=True)\n    pbd = map_column(pbd, \'phone_brand\')\n    pbd = map_column(pbd, \'device_model\')\n\n    # Train\n    print(\'Read train...\')\n    train = pd.read_csv("../input/gender_age_train.csv", dtype={\'device_id\': np.str})\n    train = map_column(train, \'group\')\n    train = train.drop([\'age\'], axis=1)\n    train = train.drop([\'gender\'], axis=1)\n    train = pd.merge(train, pbd, how=\'left\', on=\'device_id\', left_index=True)\n    train = pd.merge(train, events_small, how=\'left\', on=\'device_id\', left_index=True)\n    train.fillna(-1, inplace=True)\n\n    # Test\n    print(\'Read test...\')\n    test = pd.read_csv("../input/gender_age_test.csv", dtype={\'device_id\': np.str})\n    test = pd.merge(test, pbd, how=\'left\', on=\'device_id\', left_index=True)\n    test = pd.merge(test, events_small, how=\'left\', on=\'device_id\', left_index=True)\n    test.fillna(-1, inplace=True)\n\n    # Features\n    features = list(test.columns.values)\n    features.remove(\'device_id\')\n\n    return train, test, features\n\n\ntrain, test, features = read_train_test()\nprint(\'Length of train: \', len(train))\nprint(\'Length of test: \', len(test))\nprint(\'Features [{}]: {}\'.format(len(features), sorted(features)))\ntest_prediction, score = run_xgb(train, test, features, \'group\')\nprint("LS: {}".format(round(score, 5)))\ncreate_submission(score, test, test_prediction)\n\''}, {'role': 'assistant', 'content': 'helper_functions'}]