{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"scrolled":true},"cell_type":"code","source":"# Prepare ludwig\n!pip install ludwig\n!python -m spacy download en","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"\n# 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)\nfrom ludwig import LudwigModel # For ludwig\n\nfrom tqdm import tqdm_notebook\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, io\nimport requests\nimport tempfile, shutil\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c077e65faf967ad871579e4b4b427bdab91b9cea"},"cell_type":"code","source":"print(os.listdir(\"../input\"))\nprint(os.listdir(\"../input/histopathologic-cancer-detection\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2453d8d23c518c431ea834385b1b2b31d1241c6a","scrolled":true},"cell_type":"code","source":"train_file = '../input/histcancer-wpaths3/1_train_labels.csv'\ntrain_df = pd.read_csv(train_file)\ntrain_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ffbc2b98fd9be83096093d06cb15b1430c882a0b"},"cell_type":"code","source":"test_file = '../input/histcancer-wpaths3/1_sample_submission.csv'\ntest_df = pd.read_csv(test_file)\ntest_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"76ce348a1583d0c2697346c6914d035f0b436a66"},"cell_type":"code","source":"train_df.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cd3fd32ce8e379589140bb2baca9eb8f9906d6a2"},"cell_type":"code","source":"test_df.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1228891c5b85f349256a06c3c5e793b5849b3010"},"cell_type":"code","source":"model_definition = {\n    \"input_features\": [{\n            \"name\": \"id\",\n            \"type\": \"image\",\n            \"encoder\": \"stacked_cnn\"\n        }\n    ], \n    \"output_features\": [{\n            \"name\": \"label\", \n            \"type\": \"category\"\n        }\n     ],\n    \"training\": {\"epochs\": 10}\n}\nludwig_model = LudwigModel(model_definition,\n                           logging_level=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"70356ba77e9dd016e70a5ad7d3083978aa5f06de"},"cell_type":"code","source":"train_stats = ludwig_model.train(data_csv=train_file,\n                                skip_save_model=True,\n                                skip_save_progress=True,\n                                skip_save_log=True,\n                                skip_save_processed_input=True,\n                                logging_level=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1b62b3fee5bde8c7fbafec168e80e4bb690f5eb2"},"cell_type":"code","source":"train_stats","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"85eaf7a781b7aba6973392ebe1989a9183a05679"},"cell_type":"code","source":"dir(ludwig_model)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ffd90af824785b939237dc153aeccda663e8dcce"},"cell_type":"code","source":"for i in dir(ludwig_model):\n    print(i)\n    print(dir(i))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d8b865bc79edf2f792a3591854910e05c45cbf57"},"cell_type":"code","source":"predictions = ludwig_model.test(data_csv=test_file,\n                                   #data_df=test_df,\n                                   return_type='dict',\n                                  logging_level=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ccbcc9c49bd8c40835319ac51726907a1ee18ae3"},"cell_type":"code","source":"model.close()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c28d86a34ead1bc3a84d1e41c0a2bf1bbea24269"},"cell_type":"code","source":"for i in predictions:\n    print(i)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2b84a17c499159e6a7dfee4ee35005dc6e61887c"},"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}