Skip to content

Instantly share code, notes, and snippets.

@gleeb
Last active August 7, 2022 11:08
Show Gist options
  • Save gleeb/958484142105408849c6bfd3e67feefb to your computer and use it in GitHub Desktop.
Save gleeb/958484142105408849c6bfd3e67feefb to your computer and use it in GitHub Desktop.
titanic-train-invoke-notebook.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sagemaker\n",
"from sagemaker import get_execution_role\n",
"from sagemaker.sklearn.estimator import SKLearn"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sagemaker_session = sagemaker.Session()\n",
"role = get_execution_role()\n",
"role"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"train_input = sagemaker_session.upload_data(\"train.csv\")\n",
"train_input"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"script_path = 'sklearn-titanic-train-job.py'\n",
"\n",
"sklearn = SKLearn(\n",
" source_dir=\"code/\",\n",
" entry_point=script_path,\n",
" instance_type=\"ml.m4.xlarge\",\n",
" framework_version=\"0.20.0\",\n",
" py_version=\"py3\",\n",
" role=role,\n",
" sagemaker_session=sagemaker_session)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sklearn.fit({'train': train_input})"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"deployment = sklearn.deploy(initial_instance_count=1, instance_type=\"ml.t2.medium\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"deployment.endpoint"
]
}
],
"metadata": {
"instance_type": "ml.t3.medium",
"kernelspec": {
"display_name": "Python 3 (Data Science)",
"language": "python",
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0"
},
"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.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment