{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "02_pytorch_classification_video.ipynb",
"provenance": [],
"collapsed_sections": [],
"toc_visible": true,
"authorship_tag": "ABX9TyNSFQyw5ZIDs6dTbkog11Nm",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"source": [
"# 02. Neural Network classification with PyTorch\n",
"\n",
"Classification is a problem of predicting whether something is one thing or another (there can be multiple things as the options).\n",
"\n",
"* Book version of this notebook - https://www.learnpytorch.io/02_pytorch_classification/\n",
"* All other resources - https://github.com/mrdbourke/pytorch-deep-learning\n",
"* Stuck? Ask a question - https://github.com/mrdbourke/pytorch-deep-learning/discussions"
],
"metadata": {
"id": "BZ0Xn7qVenp8"
}
},
{
"cell_type": "markdown",
"source": [
"## 1. Make classification data and get it ready"
],
"metadata": {
"id": "0exlIszJfBFB"
}
},
{
"cell_type": "code",
"source": [
"import sklearn"
],
"metadata": {
"id": "ywkhYun3fW3a"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from sklearn.datasets import make_circles\n",
"\n",
"# Make 1000 samples\n",
"n_samples = 1000\n",
"\n",
"# Create circles\n",
"X, y = make_circles(n_samples,\n",
" noise=0.03,\n",
" random_state=42)"
],
"metadata": {
"id": "o5ssZfgjfUC2"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"len(X), len(y)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "96fM0MUYfrhg",
"outputId": "02fcd93b-2c04-48d5-b73d-de432903120d"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(1000, 1000)"
]
},
"metadata": {},
"execution_count": 3
}
]
},
{
"cell_type": "code",
"source": [
"print(f\"First 5 samples of X:\\n {X[:5]}\")\n",
"print(f\"First 5 samples of y:\\n {y[:5]}\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ew1Hds-dftUS",
"outputId": "8ee6a91e-1f01-4563-a524-20903b03820f"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"First 5 samples of X:\n",
" [[ 0.75424625 0.23148074]\n",
" [-0.75615888 0.15325888]\n",
" [-0.81539193 0.17328203]\n",
" [-0.39373073 0.69288277]\n",
" [ 0.44220765 -0.89672343]]\n",
"First 5 samples of y:\n",
" [1 1 1 1 0]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Make DataFrame of circle data\n",
"import pandas as pd\n",
"circles = pd.DataFrame({\"X1\": X[:, 0], \n",
" \"X2\": X[:, 1],\n",
" \"label\": y})\n",
"circles.head(10)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 363
},
"id": "yCU7lYZ9gFAf",
"outputId": "fb60f6e0-905f-4ca7-a586-a697bf010503"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" X1 X2 label\n",
"0 0.754246 0.231481 1\n",
"1 -0.756159 0.153259 1\n",
"2 -0.815392 0.173282 1\n",
"3 -0.393731 0.692883 1\n",
"4 0.442208 -0.896723 0\n",
"5 -0.479646 0.676435 1\n",
"6 -0.013648 0.803349 1\n",
"7 0.771513 0.147760 1\n",
"8 -0.169322 -0.793456 1\n",
"9 -0.121486 1.021509 0"
],
"text/html": [
"\n",
"
| \n", " | X1 | \n", "X2 | \n", "label | \n", "
|---|---|---|---|
| 0 | \n", "0.754246 | \n", "0.231481 | \n", "1 | \n", "
| 1 | \n", "-0.756159 | \n", "0.153259 | \n", "1 | \n", "
| 2 | \n", "-0.815392 | \n", "0.173282 | \n", "1 | \n", "
| 3 | \n", "-0.393731 | \n", "0.692883 | \n", "1 | \n", "
| 4 | \n", "0.442208 | \n", "-0.896723 | \n", "0 | \n", "
| 5 | \n", "-0.479646 | \n", "0.676435 | \n", "1 | \n", "
| 6 | \n", "-0.013648 | \n", "0.803349 | \n", "1 | \n", "
| 7 | \n", "0.771513 | \n", "0.147760 | \n", "1 | \n", "
| 8 | \n", "-0.169322 | \n", "-0.793456 | \n", "1 | \n", "
| 9 | \n", "-0.121486 | \n", "1.021509 | \n", "0 | \n", "