Skip to content

Commit 1fd6c49

Browse files
committed
suggested corrections added
1 parent db4659d commit 1fd6c49

File tree

1 file changed

+45
-51
lines changed

1 file changed

+45
-51
lines changed

samples/04_gis_analysts_data_scientists/classifying_human_activity_using _tabPFN_classifier.ipynb

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"## Leveraging TabPFN for Human Activity Recognition Using Mobile dataset"
7+
"## Leveraging TabPFN for Human Activity Recognition Using Mobile Dataset"
88
]
99
},
1010
{
@@ -16,14 +16,14 @@
1616
"* [Necessary imports](#2)\n",
1717
"* [Connecting to ArcGIS](#3)\n",
1818
"* [Accessing the datasets](#4) \n",
19-
"* [Prepare training data for TabFPN](#5)\n",
20-
" * [Data Preprocessing for tabFPN Classifier Model](#6) \n",
19+
"* [Prepare training data for TabPFN](#5)\n",
20+
" * [Data Preprocessing for TabPFN Classifier Model](#6) \n",
2121
" * [Visualize training data](#9)\n",
2222
"* [Model Training](#10) \n",
23-
" * [Define the tabFPN classifier model ](#11)\n",
23+
" * [Define the TabPFN classifier model ](#11)\n",
2424
" * [Fit the model](#12)\n",
2525
" * [Visualize results in validation set](#13)\n",
26-
"* [Predicting using tabFPN classifier model](#14)\n",
26+
"* [Predicting using TabPFN classifier model](#14)\n",
2727
" * [Predict using the trained model](#15)\n",
2828
"* [Accuracy assessment: Compute Model Metric](#16)\n",
2929
"* [Conclusion](#17)"
@@ -67,8 +67,6 @@
6767
}
6868
],
6969
"source": [
70-
"%%time\n",
71-
"\n",
7270
"%matplotlib inline\n",
7371
"import matplotlib.pyplot as plt\n",
7472
"\n",
@@ -77,7 +75,6 @@
7775
"from sklearn.preprocessing import StandardScaler\n",
7876
"from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, classification_report\n",
7977
"\n",
80-
"import arcgis\n",
8178
"from arcgis.gis import GIS\n",
8279
"from arcgis.learn import MLModel, prepare_tabulardata"
8380
]
@@ -102,9 +99,9 @@
10299
"cell_type": "markdown",
103100
"metadata": {},
104101
"source": [
105-
"## Accessing the dataset <a class=\"anchor\" id=\"4\"></a>\n",
102+
"## Accessing the datasets <a class=\"anchor\" id=\"4\"></a>\n",
106103
"\n",
107-
"The HAR training dataset consists of 1,020 rows and 561 features, capturing sensor data from mobile devices to classify human activities like walking, running, and sitting. The data includes measurements from accelerometers, gyroscopes, and GPS, providing insights into movement patterns while ensuring that location data remains anonymized for privacy protection. Features such as BodyAcc (body accelerometer), GravityAcc (gravity accelerometer), BodyAccJerk, BodyGyro (body gyroscope), and BodyGyroJerk are used to capture dynamic and rotational movements. Time-domain and frequency-domain features are extracted from these raw signals, helping to distinguish between various activities based on patterns in acceleration, rotation, and speed, making the dataset ideal for activity classification tasks."
104+
"Here we will access the train and test datasets. The Human Activity Recognition (HAR) training dataset consists of 1,020 rows and 561 features, capturing sensor data from mobile devices to classify human activities like walking, running, and sitting. The data includes measurements from accelerometers, gyroscopes, and GPS, providing insights into movement patterns while ensuring that location data remains anonymized for privacy protection. Features such as BodyAcc (body accelerometer), GravityAcc (gravity accelerometer), BodyAccJerk, BodyGyro (body gyroscope), and BodyGyroJerk are used to capture dynamic and rotational movements. Time-domain and frequency-domain features are extracted from these raw signals, helping to distinguish between various activities based on patterns in acceleration, rotation, and speed, making the dataset ideal for activity classification tasks."
108105
]
109106
},
110107
{
@@ -153,7 +150,7 @@
153150
"metadata": {},
154151
"outputs": [],
155152
"source": [
156-
"# Download the train datas and save ing it in local folder\n",
153+
"# Download the train data and saving it in local folder\n",
157154
"data_path = data_table.get_data()"
158155
]
159156
},
@@ -391,7 +388,7 @@
391388
}
392389
],
393390
"source": [
394-
"# Read the donwloaded data\n",
391+
"# Read the downloaded data\n",
395392
"train_har_data = pd.read_csv(data_path)\n",
396393
"train_har_data.head(5)"
397394
]
@@ -420,7 +417,7 @@
420417
"cell_type": "markdown",
421418
"metadata": {},
422419
"source": [
423-
"Next we will access the test dataset, which is a larger dataset containing 6,332 samples. "
420+
"Next, we will access the test dataset, which is significantly larger, containing 6,332 samples."
424421
]
425422
},
426423
{
@@ -469,7 +466,7 @@
469466
"metadata": {},
470467
"outputs": [],
471468
"source": [
472-
"# Download the test data and save it in local folder\n",
469+
"# Download the test data and save it to a local folder\n",
473470
"test_data_path = test_data_table.get_data()"
474471
]
475472
},
@@ -736,7 +733,7 @@
736733
"cell_type": "markdown",
737734
"metadata": {},
738735
"source": [
739-
"## Prepare training data for TabFPN <a class=\"anchor\" id=\"5\"></a>"
736+
"## Prepare training data for TabPFN <a class=\"anchor\" id=\"5\"></a>"
740737
]
741738
},
742739
{
@@ -1354,14 +1351,14 @@
13541351
"cell_type": "markdown",
13551352
"metadata": {},
13561353
"source": [
1357-
"### Data Preprocessing for tabFPN Classifier Model<a class=\"anchor\" id=\"6\"></a>"
1354+
"### Data Preprocessing for TabPFN Classifier Model<a class=\"anchor\" id=\"6\"></a>"
13581355
]
13591356
},
13601357
{
13611358
"cell_type": "markdown",
13621359
"metadata": {},
13631360
"source": [
1364-
"To process the training data for the TabPFN model, we will use Linear Discriminant Analysis (LDA) to reduce the number of features from the original 560 to below the tabFPN model's maximum limit of 100. By applying LDA, we can preserve the most relevant information for classification while reducing the complexity of the input data, making it suitable for the TabPFN model, which requires a compact input format for efficient processing and predictions."
1361+
"To process the training data for the TabPFN model, we will use Linear Discriminant Analysis (LDA) to reduce the number of features from the original 561 to below the TabPFN model's maximum limit of 100. By applying LDA, we can preserve the most relevant information for classification while reducing the complexity of the input data, making it suitable for the TabPFN model, which requires a compact input format for efficient processing and predictions."
13651362
]
13661363
},
13671364
{
@@ -1381,7 +1378,7 @@
13811378
}
13821379
],
13831380
"source": [
1384-
"# Data processing to reduce the features to 100 or less as required for tabFPN models\n",
1381+
"# Data processing to reduce the features to 100 or less as required for TabPFN models\n",
13851382
"X = train_har_data.drop(columns=['Activity'])\n",
13861383
"y = train_har_data['Activity']\n",
13871384
"scaler = StandardScaler()\n",
@@ -1395,54 +1392,62 @@
13951392
},
13961393
{
13971394
"cell_type": "code",
1398-
"execution_count": 35,
1395+
"execution_count": 36,
13991396
"metadata": {},
14001397
"outputs": [
14011398
{
14021399
"data": {
14031400
"text/plain": [
1404-
"5"
1401+
"Index(['LDA1', 'LDA2', 'LDA3', 'LDA4', 'LDA5', 'Activity'], dtype='object')"
14051402
]
14061403
},
1407-
"execution_count": 35,
1404+
"execution_count": 36,
14081405
"metadata": {},
14091406
"output_type": "execute_result"
14101407
}
14111408
],
14121409
"source": [
1413-
"# define the explanatory vairables\n",
1414-
"X = list(X_train_lda_df.columns)\n",
1415-
"X =X[:-1]\n",
1416-
"len(X)"
1410+
"# Visualize the final processed training data columns\n",
1411+
"X_train_lda_df.columns"
1412+
]
1413+
},
1414+
{
1415+
"cell_type": "markdown",
1416+
"metadata": {},
1417+
"source": [
1418+
"In the above training dataframe we will use the `Activity` as the target label to be predicted using rest of the features as explanatory variables `X`. We define the explanatory variables as follows: "
14171419
]
14181420
},
14191421
{
14201422
"cell_type": "code",
1421-
"execution_count": 36,
1423+
"execution_count": 35,
14221424
"metadata": {},
14231425
"outputs": [
14241426
{
14251427
"data": {
14261428
"text/plain": [
1427-
"Index(['LDA1', 'LDA2', 'LDA3', 'LDA4', 'LDA5', 'Activity'], dtype='object')"
1429+
"5"
14281430
]
14291431
},
1430-
"execution_count": 36,
1432+
"execution_count": 35,
14311433
"metadata": {},
14321434
"output_type": "execute_result"
14331435
}
14341436
],
14351437
"source": [
1436-
"X_train_lda_df.columns"
1438+
"# define the explanatory vairables\n",
1439+
"X = list(X_train_lda_df.columns)\n",
1440+
"X =X[:-1]\n",
1441+
"len(X)"
14371442
]
14381443
},
14391444
{
14401445
"cell_type": "markdown",
14411446
"metadata": {},
14421447
"source": [
1443-
"Once the explanatory variables X are preprocessed this is now used as input for the *prepare_tabulardata* method from the tabular learner in the arcgis.learn. The method takes the feature layer or a spatial dataframe containing the dataset and prepares it for fitting the model. \n",
1448+
"Once the explanatory variables `X` is defined, this is now used as input in the `prepare_tabulardata` method from the tabular learner in the `arcgis.learn`. The method takes the feature layer or a spatial dataframe containing the dataset and prepares it for fitting the model. \n",
14441449
"\n",
1445-
"The input parameters required for the tool are similar to the ones mentioned previously :"
1450+
"The input parameters required for the tool are used as shown here :"
14461451
]
14471452
},
14481453
{
@@ -1465,7 +1470,7 @@
14651470
"cell_type": "markdown",
14661471
"metadata": {},
14671472
"source": [
1468-
"To get a sense of what the training data looks like, the show_batch() method will randomly pick a few training sample and visualize them. The sample are showing the explanaotyr vairables and the variblss to predict column."
1473+
"To get a sense of what the training data looks like, the `show_batch()` method will randomly pick a few training sample and visualize them. The sample are showing the explanatory variables and the `Activity` target label to predict."
14691474
]
14701475
},
14711476
{
@@ -1582,9 +1587,9 @@
15821587
"cell_type": "markdown",
15831588
"metadata": {},
15841589
"source": [
1585-
"### Define the tabFPN classifier model <a class=\"anchor\" id=\"11\"></a>\n",
1590+
"### Define the TabPFN classifier model <a class=\"anchor\" id=\"11\"></a>\n",
15861591
"\n",
1587-
"The default, initialization of the tabFPN classifier model object is shown below:"
1592+
"The default, initialization of the TabPFN classifier model object is shown below:"
15881593
]
15891594
},
15901595
{
@@ -1593,7 +1598,6 @@
15931598
"metadata": {},
15941599
"outputs": [],
15951600
"source": [
1596-
"from arcgis.learn import MLModel\n",
15971601
"tabpfn_classifier = MLModel(data, 'tabpfn.TabPFNClassifier',device='cpu', N_ensemble_configurations=32)"
15981602
]
15991603
},
@@ -1639,7 +1643,7 @@
16391643
"cell_type": "markdown",
16401644
"metadata": {},
16411645
"source": [
1642-
"We can see the model score is showing excellent result."
1646+
"We can see the model score is showing excellent results."
16431647
]
16441648
},
16451649
{
@@ -1770,7 +1774,7 @@
17701774
"cell_type": "markdown",
17711775
"metadata": {},
17721776
"source": [
1773-
"## Predicting using the tabFPN classifier model <a class=\"anchor\" id=\"14\"></a>\n",
1777+
"## Predicting using the TabPFN classifier model <a class=\"anchor\" id=\"14\"></a>\n",
17741778
"\n",
17751779
"Once the TabPFN classifier is trained on the smaller dataset of 1,020 samples, we can use it to predict the classes of a larger dataset containing 6,332 samples. Given TabPFN’s ability to process data efficiently with a single forward pass, it can handle this larger dataset quickly, classifying each sample based on the patterns learned during training. Since the model is optimized for fast and scalable predictions, it will generate class predictions for all samples. \n",
17761780
"\n",
@@ -2042,17 +2046,7 @@
20422046
"source": [
20432047
"### Accuracy assessment <a class=\"anchor\" id=\"16\"></a>\n",
20442048
"\n",
2045-
"Here we weill evaluate the model's performance. This will print out multiple model metrics. we can assess the model quality using its corresponding metrics. These metrics include a combination of multiple evaluation criteria, such as `accuracy`, `precision`, `recall` and `F1-Score`, which collectively measure the model's performance on the validation set."
2046-
]
2047-
},
2048-
{
2049-
"cell_type": "code",
2050-
"execution_count": 47,
2051-
"metadata": {},
2052-
"outputs": [],
2053-
"source": [
2054-
"import pandas as pd\n",
2055-
"from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, classification_report"
2049+
"Here we will evaluate the model's performance. This will print out multiple model metrics. we can assess the model quality using its corresponding metrics. These metrics include a combination of multiple evaluation criteria, such as `accuracy`, `precision`, `recall` and `F1-Score`, which collectively measure the model's performance on the validation set."
20562050
]
20572051
},
20582052
{
@@ -2146,9 +2140,9 @@
21462140
],
21472141
"metadata": {
21482142
"kernelspec": {
2149-
"display_name": "pro3.4_climax_27October2024",
2143+
"display_name": "pro3.4_climaxAug2024",
21502144
"language": "python",
2151-
"name": "pro3.4_climax_27october2024"
2145+
"name": "pro3.4_climaxaug2024"
21522146
},
21532147
"language_info": {
21542148
"codemirror_mode": {
@@ -2160,7 +2154,7 @@
21602154
"name": "python",
21612155
"nbconvert_exporter": "python",
21622156
"pygments_lexer": "ipython3",
2163-
"version": "3.11.9"
2157+
"version": "3.11.8"
21642158
}
21652159
},
21662160
"nbformat": 4,

0 commit comments

Comments
 (0)