{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","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\nimport numpy as np # linear algebra\nimport 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\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train_df = pd.read_csv('../input/train.csv')\ntest_df = pd.read_csv('../input/test.csv')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7c494c6fe58571785232489dc108267f4594ccd7"},"cell_type":"code","source":"train_df['first_active_month'] = pd.to_datetime(train_df['first_active_month'])\ntrain_df['first_active_month'] = pd.to_numeric(train_df['first_active_month'])\n\ntest_df['first_active_month'] = pd.to_datetime(test_df['first_active_month'])\ntest_df['first_active_month'] = pd.to_numeric(test_df['first_active_month'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a82c2754bf92ae8f1ab8f6bbabbb0c2ab624a8c0"},"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"060e26ad925905ca0f008fb59cd5086a093cd0f2"},"cell_type":"code","source":"X = train_df.drop(['card_id','target'],axis=1)\ny = train_df['target']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7771ea30f2d8a74db523f7b16934e8ad1ddd7d98"},"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b71447521a61b3e1832e09254c7b23a11cbf87b3"},"cell_type":"code","source":"from sklearn.metrics import mean_squared_error\nimport numpy as np\n\nrf = RandomForestRegressor(max_depth=2,n_estimators=200)\nrf.fit(X_train,y_train)\n\npred = rf.predict(X_test)\nprint(np.sqrt(mean_squared_error(pred,y_test)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fa88123ca70ce001aa5fe00f0fa5ba407a7a1ee1"},"cell_type":"code","source":"rf.fit(X,y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dbda867706ad5108c1066f00d2aff370598be689"},"cell_type":"code","source":"index = test_df['card_id']\ntest = test_df.drop(['card_id'],axis=1)\n\npred = rf.predict(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"97fe56db778c511bb7511e818a96e77fa7e34b8e"},"cell_type":"code","source":"dfdict = {}\ndfdict[\"card_id\"]=index\ndfdict[\"target\"]=pred\n\ndf=pd.DataFrame(dfdict)\ndf.to_csv(\"solution.csv\",index=False,columns=[\"card_id\",\"target\"])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"797d76649bceed7fe614b46f23ef12a184174dcf"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}