Skip to content

Commit 414ad71

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Improve definition of feature_names on the churn notebook to avoid problems when running the cell twice
1 parent 03e3d99 commit 414ad71

File tree

1 file changed

+63
-48
lines changed

1 file changed

+63
-48
lines changed

β€Žexamples/tabular-classification/sklearn/churn-classifier/churn-classifier-sklearn.ipynb

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 2,
52+
"execution_count": 1,
5353
"id": "33179b0c",
5454
"metadata": {},
5555
"outputs": [],
@@ -72,7 +72,7 @@
7272
},
7373
{
7474
"cell_type": "code",
75-
"execution_count": 3,
75+
"execution_count": 2,
7676
"id": "83470097",
7777
"metadata": {},
7878
"outputs": [],
@@ -82,7 +82,7 @@
8282
},
8383
{
8484
"cell_type": "code",
85-
"execution_count": 12,
85+
"execution_count": 3,
8686
"id": "40472b51",
8787
"metadata": {},
8888
"outputs": [],
@@ -92,7 +92,7 @@
9292
},
9393
{
9494
"cell_type": "code",
95-
"execution_count": 14,
95+
"execution_count": 4,
9696
"id": "679e0b36",
9797
"metadata": {},
9898
"outputs": [
@@ -308,7 +308,7 @@
308308
"[10000 rows x 10 columns]"
309309
]
310310
},
311-
"execution_count": 14,
311+
"execution_count": 4,
312312
"metadata": {},
313313
"output_type": "execute_result"
314314
}
@@ -329,7 +329,7 @@
329329
},
330330
{
331331
"cell_type": "code",
332-
"execution_count": 15,
332+
"execution_count": 5,
333333
"id": "708ade4c",
334334
"metadata": {},
335335
"outputs": [],
@@ -347,7 +347,7 @@
347347
},
348348
{
349349
"cell_type": "code",
350-
"execution_count": 16,
350+
"execution_count": 6,
351351
"id": "e0a1b4b0",
352352
"metadata": {},
353353
"outputs": [],
@@ -367,7 +367,7 @@
367367
},
368368
{
369369
"cell_type": "code",
370-
"execution_count": 17,
370+
"execution_count": 7,
371371
"id": "248556af",
372372
"metadata": {},
373373
"outputs": [
@@ -632,7 +632,7 @@
632632
"[10000 rows x 13 columns]"
633633
]
634634
},
635-
"execution_count": 17,
635+
"execution_count": 7,
636636
"metadata": {},
637637
"output_type": "execute_result"
638638
}
@@ -654,7 +654,7 @@
654654
},
655655
{
656656
"cell_type": "code",
657-
"execution_count": 18,
657+
"execution_count": 8,
658658
"id": "b76d541a",
659659
"metadata": {},
660660
"outputs": [],
@@ -674,7 +674,7 @@
674674
},
675675
{
676676
"cell_type": "code",
677-
"execution_count": 19,
677+
"execution_count": 9,
678678
"id": "ee882b61",
679679
"metadata": {
680680
"scrolled": true
@@ -686,7 +686,7 @@
686686
"LogisticRegression(random_state=1300)"
687687
]
688688
},
689-
"execution_count": 19,
689+
"execution_count": 9,
690690
"metadata": {},
691691
"output_type": "execute_result"
692692
}
@@ -698,7 +698,7 @@
698698
},
699699
{
700700
"cell_type": "code",
701-
"execution_count": 20,
701+
"execution_count": 10,
702702
"id": "a4f603d9",
703703
"metadata": {
704704
"scrolled": true
@@ -756,7 +756,7 @@
756756
},
757757
{
758758
"cell_type": "code",
759-
"execution_count": 21,
759+
"execution_count": 11,
760760
"id": "82a38cd9",
761761
"metadata": {},
762762
"outputs": [],
@@ -776,15 +776,15 @@
776776
},
777777
{
778778
"cell_type": "code",
779-
"execution_count": 22,
779+
"execution_count": 12,
780780
"id": "5562a940",
781781
"metadata": {},
782782
"outputs": [
783783
{
784784
"name": "stdout",
785785
"output_type": "stream",
786786
"text": [
787-
"Created your project. Navigate to http://localhost:8000/projects/1 to see it in the UI.\n"
787+
"Created your project. Navigate to http://staging.unbox.ai/projects/50 to see it in the UI.\n"
788788
]
789789
}
790790
],
@@ -806,42 +806,25 @@
806806
},
807807
{
808808
"cell_type": "code",
809-
"execution_count": 29,
809+
"execution_count": 15,
810810
"id": "7355e02d",
811811
"metadata": {},
812-
"outputs": [
813-
{
814-
"name": "stderr",
815-
"output_type": "stream",
816-
"text": [
817-
"/var/folders/9z/j3bd32nd47j_l0thnbj6vbnw0000gn/T/ipykernel_17091/2793504704.py:6: SettingWithCopyWarning: \n",
818-
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
819-
"Try using .loc[row_indexer,col_indexer] = value instead\n",
820-
"\n",
821-
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
822-
" x_val['churn'] = y_val.values\n",
823-
"/var/folders/9z/j3bd32nd47j_l0thnbj6vbnw0000gn/T/ipykernel_17091/2793504704.py:7: SettingWithCopyWarning: \n",
824-
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
825-
"Try using .loc[row_indexer,col_indexer] = value instead\n",
826-
"\n",
827-
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
828-
" x_train['churn'] = y_train.values\n"
829-
]
830-
}
831-
],
812+
"outputs": [],
832813
"source": [
833814
"# Some variables that will be used for the dataset upload\n",
834815
"class_names = [\"Retained\", \"Exited\"]\n",
835816
"feature_names = list(x_val.columns)\n",
836817
"\n",
837-
"# Add the ground truths to the ordinal dataset for Unbox\n",
838-
"x_val['churn'] = y_val.values\n",
839-
"x_train['churn'] = y_train.values"
818+
"# Add the ground truths to the original dataset for Unbox\n",
819+
"validation_set = x_val.copy()\n",
820+
"validation_set['churn'] = y_val.values\n",
821+
"training_set = x_train.copy()\n",
822+
"training_set['churn'] = y_train.values"
840823
]
841824
},
842825
{
843826
"cell_type": "code",
844-
"execution_count": 24,
827+
"execution_count": 16,
845828
"id": "197e51c6",
846829
"metadata": {},
847830
"outputs": [
@@ -851,11 +834,18 @@
851834
"text": [
852835
"Adding your dataset to Unbox! Check out the project page to have a look.\n"
853836
]
837+
},
838+
{
839+
"name": "stderr",
840+
"output_type": "stream",
841+
"text": [
842+
"100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 91.9k/91.9k [00:02<00:00, 33.2kB/s]\n"
843+
]
854844
}
855845
],
856846
"source": [
857847
"dataset = project.add_dataframe(\n",
858-
" df=x_val,\n",
848+
" df=validation_set,\n",
859849
" class_names=class_names,\n",
860850
" label_column_name='churn',\n",
861851
" commit_message='first commit!',\n",
@@ -882,7 +872,7 @@
882872
},
883873
{
884874
"cell_type": "code",
885-
"execution_count": 25,
875+
"execution_count": 17,
886876
"id": "d233987d",
887877
"metadata": {},
888878
"outputs": [],
@@ -905,7 +895,7 @@
905895
},
906896
{
907897
"cell_type": "code",
908-
"execution_count": 26,
898+
"execution_count": 18,
909899
"id": "674147b8",
910900
"metadata": {},
911901
"outputs": [
@@ -917,7 +907,7 @@
917907
" [0.81455616, 0.18544384]])"
918908
]
919909
},
920-
"execution_count": 26,
910+
"execution_count": 18,
921911
"metadata": {},
922912
"output_type": "execute_result"
923913
}
@@ -936,17 +926,42 @@
936926
},
937927
{
938928
"cell_type": "code",
939-
"execution_count": 27,
929+
"execution_count": 19,
940930
"id": "ace580e8",
941931
"metadata": {},
942932
"outputs": [
943933
{
944934
"name": "stdout",
945935
"output_type": "stream",
946936
"text": [
947-
"Bundling model and artifacts...\n",
937+
"Bundling model and artifacts...\n"
938+
]
939+
},
940+
{
941+
"name": "stderr",
942+
"output_type": "stream",
943+
"text": [
944+
"/Users/gustavocid/Desktop/unbox-repos/unboxapi-python-client/unboxapi/api.py:125: ResourceWarning: unclosed <ssl.SSLSocket fd=83, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.8.253.206', 53878), raddr=('108.156.83.110', 443)>\n",
945+
" return self._api_request(\"GET\", endpoint, headers=self._headers, params=params)\n",
946+
"ResourceWarning: Enable tracemalloc to get the object allocation traceback\n",
947+
"100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 53.7k/53.7k [00:02<00:00, 22.0kB/s]\n"
948+
]
949+
},
950+
{
951+
"name": "stdout",
952+
"output_type": "stream",
953+
"text": [
948954
"Adding your model to Unbox! Check out the project page to have a look.\n"
949955
]
956+
},
957+
{
958+
"name": "stderr",
959+
"output_type": "stream",
960+
"text": [
961+
"/Users/gustavocid/Desktop/unbox-repos/unboxapi-python-client/unboxapi/api.py:129: ResourceWarning: unclosed <ssl.SSLSocket fd=83, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.8.253.206', 53880), raddr=('108.156.83.110', 443)>\n",
962+
" return self._api_request(\n",
963+
"ResourceWarning: Enable tracemalloc to get the object allocation traceback\n"
964+
]
950965
}
951966
],
952967
"source": [
@@ -960,7 +975,7 @@
960975
" name='Churn Classifier',\n",
961976
" commit_message='this is my churn classification model',\n",
962977
" feature_names=feature_names,\n",
963-
" train_sample_df=x_train[:3000],\n",
978+
" train_sample_df=training_set[:3000],\n",
964979
" train_sample_label_column_name='churn',\n",
965980
" categorical_feature_names=[\"Gender\", \"Geography\"],\n",
966981
" col_names=feature_names,\n",

0 commit comments

Comments
Β (0)