{"metadata":{"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,"cells":[{"cell_type":"code","execution_count":32,"metadata":{"collapsed":false,"_cell_guid":"4b1487f4-321c-6b67-3ee9-e7a6e0dcd3c1","_active":false},"outputs":[],"source":"import os, time, pandas as pd,numpy as np\nfrom shapely.geometry.polygon import LinearRing, Polygon\nfrom shapely.ops import cascaded_union\nfrom matplotlib import pyplot\nfrom shapely.wkt import dumps, loads\nimport PIL as pil\nfrom PIL import Image, ImageDraw\ndata_dir = \"../input\"","execution_state":"idle"},{"cell_type":"code","execution_count":3,"metadata":{"collapsed":false,"_cell_guid":"22bd9b11-2990-c925-46c9-912d98bbc04f","_active":false},"outputs":[],"source":"labels = pd.read_csv(os.path.join(data_dir, \"train_wkt_v4.csv\"))","execution_state":"idle"},{"cell_type":"code","execution_count":40,"metadata":{"collapsed":false,"scrolled":true,"_cell_guid":"d0911dc6-1706-b908-e568-487b39a4a191","_active":true},"outputs":[],"source":"labels.head(15)"},{"cell_type":"code","execution_count":17,"metadata":{"collapsed":false,"_cell_guid":"f5d06daf-4ea1-5183-3aa5-7040ffa88f49","_active":false},"outputs":[],"source":"\n#labels.iloc[[3],[2]].values[0,0]\npol = loads(labels.iloc[[3],[2]].values[0,0])\nlist(pol)[0].bounds\n","execution_state":"idle"},{"cell_type":"code","execution_count":21,"metadata":{"collapsed":false,"_cell_guid":"7f4ca41f-6fcf-b6b9-f2b9-1d5f42c79698","_active":false},"outputs":[],"source":"#list(pol)[1].exterior.coords.xy\nnp.array(list(pol)[1])","execution_state":"idle"},{"metadata":{"_cell_guid":"391722d6-d195-309a-5987-2333da0634d1","_active":false,"collapsed":false},"source":"aaa = list(pol)[1]\nexterior = np.array(aaa.exterior.coords)\nimg = pil.Image.new('L', (1, -1), 0)\nImageDraw.Draw(img).polygon(polygon, outline=1, fill=1)\nmask = numpy.array(img)","execution_count":33,"cell_type":"code","outputs":[],"execution_state":"idle"},{"cell_type":"code","execution_count":23,"metadata":{"collapsed":false,"_cell_guid":"93f169e6-8ab5-ae43-4b85-945d3dfb9007","_active":false},"outputs":[],"source":"pol.area","execution_state":"idle"},{"cell_type":"code","execution_count":24,"metadata":{"collapsed":false,"_cell_guid":"0ce23377-7fae-7c04-72b5-f5875d809be4","_active":false},"outputs":[],"source":"cascaded_union(pol).area","execution_state":"idle"},{"cell_type":"code","execution_count":69,"metadata":{"collapsed":false,"_cell_guid":"35a6811f-678b-2ea9-8567-d89022e0f500","_active":false},"outputs":[],"source":"0.3*((5-1)*0.5 - 1) + 0.8"},{"cell_type":"code","execution_count":null,"metadata":{"collapsed":true,"_cell_guid":"e5dfb293-7e5f-8832-033b-bbfa774a7825","_active":false},"outputs":[],"source":null}]}