{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "765cc74f-e8e2-b2ee-7640-e49e2ed67dea"
      },
      "source": [
        "xgboost rmse issue"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "e3409e42-93e1-d814-a20b-149e60bb1e7c"
      },
      "outputs": [],
      "source": [
        "# This Python 3 environment comes with many helpful analytics libraries installed\n",
        "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n",
        "# For example, here's several helpful packages to load in \n",
        "\n",
        "import numpy as np # linear algebra\n",
        "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
        "\n",
        "# Input data files are available in the \"../input/\" directory.\n",
        "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n",
        "\n",
        "from subprocess import check_output\n",
        "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n",
        "\n",
        "# Any results you write to the current directory are saved as output."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "bdd0aa7c-eef1-8eed-38bc-0c6029529d9e"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import xgboost as xgb\n",
        "from sklearn import datasets\n",
        "from sklearn.cross_validation import train_test_split"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "8a81ed3a-1cc1-953b-1214-b07862aebf92"
      },
      "outputs": [],
      "source": [
        "# Load data\n",
        "boston = datasets.load_boston()\n",
        "X_train, X_test, y_train, y_test = train_test_split(\n",
        "       boston.data, boston.target, test_size=0.33, random_state=42)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "6094984b-9048-d136-8949-f1734b094fd6"
      },
      "outputs": [],
      "source": [
        "dtrain = xgb.DMatrix(X_train, y_train)\n",
        "dvalid = xgb.DMatrix(X_test, y_test)\n",
        "watchlist = [(dtrain, \"train\"), (dvalid, \"eval\")]\n",
        "params = {\"objective\": \"reg:linear\",\n",
        "          \"eval_metric\": \"rmse\",\n",
        "          \"eta\": 0.01,\n",
        "          \"max_depth\": 6,\n",
        "          \"silent\": 1,\n",
        "          \"nthread\": 1}\n",
        "num_boost_round = 100\n",
        "gbm = xgb.train(params, dtrain, num_boost_round,\n",
        "                evals=watchlist, verbose_eval=True)\n",
        "y_pred = gbm.predict(dvalid)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "31836e54-ae85-a7ca-f0a1-5e0ef07a4335"
      },
      "outputs": [],
      "source": [
        "np.sqrt(np.mean((y_pred - y_test) ** 2))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "7ceabe1d-f1e3-e392-766b-3225e5226378"
      },
      "outputs": [],
      "source": ""
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.5.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}