Created
November 5, 2019 04:14
-
-
Save brianray/b5bfe76ee7ba1c65fb9f33c829682cd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import json\n", | |
"from google.cloud import automl_v1beta1 as automl" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# to regenrate test file\n", | |
"\n", | |
"# import pandas as pd\n", | |
"# df = pd.read_csv(\"file_out_2495_tags.csv\")\n", | |
"# with open(\"test_record.txt\", \"w\") as f:\n", | |
"# for col in df.columns:\n", | |
"# f.write(\"# {}: {}\\n\".format(col, df.loc[0, col]))\n", | |
"# manualy remove The Beatles or Like The Beatles\n", | |
"\n", | |
"def clean(x):\n", | |
" x = x.strip()\n", | |
" if x == \"nan\":\n", | |
" return None\n", | |
" try:\n", | |
" return float(x)\n", | |
" except:\n", | |
" return x\n", | |
"\n", | |
"test_record = [x.split(':') for x in open('test_record.txt').read().strip().split('\\n')]\n", | |
"inputs = [clean(x[1]) for x in test_record]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"payload {\n", | |
" tables {\n", | |
" score: 0.9896599650382996\n", | |
" value {\n", | |
" string_value: \"True\"\n", | |
" }\n", | |
" }\n", | |
"}\n", | |
"payload {\n", | |
" tables {\n", | |
" score: 0.010340098291635513\n", | |
" value {\n", | |
" string_value: \"False\"\n", | |
" }\n", | |
" }\n", | |
"}" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"project_id = 'mwpmltr'\n", | |
"compute_region = 'us-central1'\n", | |
"model_display_name = 'beatles_machine_l_20191104025339'\n", | |
"\n", | |
"\n", | |
"client = automl.TablesClient(project=project_id, region=compute_region)\n", | |
"\n", | |
"response = client.predict(\n", | |
" model_display_name=model_display_name,\n", | |
" inputs=inputs)\n", | |
"response" | |
] | |
} | |
], | |
"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.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment