{"cells":[
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "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\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nfrom sklearn import tree\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.ensemble import ExtraTreesRegressor\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.decomposition import PCA\nfrom sklearn.ensemble import RandomForestClassifier\nimport random\nimport ml_metrics as metrics\n\n\ntrain = pd.read_csv(\"../input/train.csv\")\ntest = pd.read_csv(\"../input/test.csv\")\ntrain.shape\ntest.shape\ntrain.head(5)\ntest_ids = set(test.accuracy.unique())\ntrain_ids = set(train.accuracy.unique())\nintersection_count = len(test_ids & train_ids)\nintersection_count == len(test_ids)\nunique_places = train.place_id.unique()\n#unique_rows = test.row_id.head(1000000)\n#print(len(unique_places))\n\nsel_place_ids = [unique_places[i] for i in sorted(random.sample(range(len(unique_places)), 100)) ]\nsel_train = train[train.place_id.isin(sel_place_ids)]\n\n#sel_row_ids = [unique_rows[i] for i in sorted(random.sample(range(len(unique_rows)), 1000000)) ]\n#sel_test = test[test.row_id.isin(sel_row_ids)]\n\n# Create the target and features numpy arrays: target, features_one\ntarget = sel_train[\"place_id\"].values\nfeatures_forest = sel_train[[\"x\", \"y\"]].values\n# Building and fitting my_forest\nforest = RandomForestClassifier(n_estimators = 1000)\nmy_forest = forest.fit(features_forest, target)\nprint(my_forest.feature_importances_)\n# Print the score of the fitted random forest\n#print(my_forest.score(features_forest, target))\n# Compute predictions on test set features then print the length of the prediction vector\ntest[\"place_id\"] = float('NaN')\ntest.info()\ntest_features = test[[\"x\", \"y\"]].values\nprint(test_features)\n#pred_forest = forest.predict(test_features)\n#print(len(pred_forest))\n#row_id =np.array(test[\"row_id\"]).astype(int)\n#my_solution = pd.DataFrame(pred_forest, row_id, columns = [\"place_id\"])\n#print(my_solution)\n#my_solution.to_csv(fb_recruit, sep='\\t')"
 }
],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}}, "nbformat": 4, "nbformat_minor": 0}