{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport sklearn\nimport catboost\nimport lightgbm\nimport xgboost\nimport pandas as pd\nimport matplotlib.pyplot as plt\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Data = pd.read_csv('../input/test_data.csv').values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def ml(a, b):\n    if a[0] < b[0]:\n        if a[2] < b[0]:\n            x = 0\n        elif a[2] < b[2]:\n            x = a[2] - b[0]\n        else:\n            x = b[2] - b[0]\n    elif a[0] < b[2]:\n        if a[2] < b[2]:\n            x = a[2] - a[0]\n        else:\n            x = b[2] - a[0]\n    else:\n        x = 0\n    if a[1] < b[1]:\n        if a[3] < b[1]:\n            y = 0\n        elif a[3] < b[3]:\n            y = a[3] - b[1]\n        else:\n            y = b[3] - b[1]\n    elif a[1] < b[3]:\n        if a[3] < b[3]:\n            y = a[3] - a[1]\n        else:\n            y = b[3] - a[1]\n    else:\n        y = 0\n    S_a = (a[2] - a[0] + 1)*(a[3] - a[1] + 1)\n    S_b = (b[2] - b[0] + 1)*(b[3] - b[1] + 1)\n    S_ab = x*y\n    return S_ab/(S_a + S_b - S_ab)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Iz = np.sort(list(set(Data[:,1])))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Answer = np.zeros([len(Iz),5], dtype= 'int32')\nfor i in range(len(Iz)):\n    B = Data[Data[:,1] == Iz[i]][:,2:]\n    S = 0\n    Y = 0\n    d = 10\n    for x_min in np.arange(np.min(B[:,0]),np.max(B[:,2]),d):\n        for y_min in np.arange(np.min(B[:,1]),np.max(B[:,3]),d):\n            for x_max in np.arange(x_min,np.max(B[:,2]),d):\n                for y_max in np.arange(y_min,np.max(B[:,3]),d):\n                    X = [x_min, y_min, x_max, y_max]\n                    s = 0\n                    for j in range(len(B)):\n                        s = s + ml(X,B[j])\n                    if s > S:\n                        Y = [x_min, y_min, x_max, y_max]\n                        S = 0 + s\n    print(i, S/len(B))\n    Answer[i,0] = Iz[i]\n    Answer[i,1] = Y[0]\n    Answer[i,2] = Y[1]\n    Answer[i,3] = Y[2]\n    Answer[i,4] = Y[3]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pd.DataFrame(Answer).to_csv('Answer.csv', header = False, index = False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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.6.0"}},"nbformat":4,"nbformat_minor":1}