Skip to content

Commit 9b6001a

Browse files
committed
alt solution to one hot encoding
1 parent 839cfae commit 9b6001a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

intro-neural-networks/student-admissions/StudentAdmissionsSolutions.ipynb

+18-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"outputs": [],
2424
"source": [
25+
"## One solution\n",
2526
"# Make dummy variables for rank\n",
2627
"one_hot_data = pd.concat([data, pd.get_dummies(data['rank'], prefix='rank')], axis=1)\n",
2728
"\n",
@@ -32,6 +33,22 @@
3233
"one_hot_data[:10]"
3334
]
3435
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": null,
39+
"metadata": {
40+
"collapsed": true
41+
},
42+
"outputs": [],
43+
"source": [
44+
"## Alternative solution ##\n",
45+
"# if you're using an up-to-date version of pandas, \n",
46+
"# you can also use selection by columns\n",
47+
"\n",
48+
"# an equally valid solution\n",
49+
"one_hot_data = pd.get_dummies(data, columns=['rank'])"
50+
]
51+
},
3552
{
3653
"cell_type": "markdown",
3754
"metadata": {},
@@ -83,7 +100,7 @@
83100
},
84101
"outputs": [],
85102
"source": [
86-
"## alternative solution ##\n",
103+
"## Alternative solution ##\n",
87104
"# you could also *only* use y and the output \n",
88105
"# and calculate sigmoid_prime directly from the activated output!\n",
89106
"\n",

0 commit comments

Comments
 (0)