Skip to content

Commit

Permalink
update m04_c04
Browse files Browse the repository at this point in the history
  • Loading branch information
aoguedao committed Jan 22, 2020
1 parent 1317a52 commit 46ef00a
Show file tree
Hide file tree
Showing 2 changed files with 752 additions and 44 deletions.
172 changes: 129 additions & 43 deletions m04_machine_learning/m04_c03_classification/m04_c03_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,102 @@
"metadata": {
"Collapsed": "false"
},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>temp_f</th>\n",
" <th>nm_bad_rings</th>\n",
" <th>temp_c</th>\n",
" <th>is_failure</th>\n",
" <th>ds_failure</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>53</td>\n",
" <td>3</td>\n",
" <td>11.67</td>\n",
" <td>1</td>\n",
" <td>Falla</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>56</td>\n",
" <td>1</td>\n",
" <td>13.33</td>\n",
" <td>1</td>\n",
" <td>Falla</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>57</td>\n",
" <td>1</td>\n",
" <td>13.89</td>\n",
" <td>1</td>\n",
" <td>Falla</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>63</td>\n",
" <td>0</td>\n",
" <td>17.22</td>\n",
" <td>0</td>\n",
" <td>Éxito</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <td>66</td>\n",
" <td>0</td>\n",
" <td>18.89</td>\n",
" <td>0</td>\n",
" <td>Éxito</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" temp_f nm_bad_rings temp_c is_failure ds_failure\n",
"0 53 3 11.67 1 Falla\n",
"1 56 1 13.33 1 Falla\n",
"2 57 1 13.89 1 Falla\n",
"3 63 0 17.22 0 Éxito\n",
"4 66 0 18.89 0 Éxito"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Un poco de procesamiento de datos\n",
"challenger = challenger.assign(\n",
" temp_c=lambda x: ((x[\"temp_f\"] - 32.) / 1.8).round(2),\n",
" is_failure=lambda x: x[\"nm_bad_rings\"].ne(0).astype(np.int),\n",
" ds_failure=lambda x: x[\"is_failure\"].map({1: \"Falla\", 0:\"Éxito\"})\n",
")"
")\n",
"challenger.head()"
]
},
{
Expand Down Expand Up @@ -4194,32 +4282,6 @@
"metadata": {
"Collapsed": "false"
},
"outputs": [
{
"data": {
"text/plain": [
"array([0.85100948, 0.77559639, 0.74473325, 0.51574021, 0.39116945,\n",
" 0.35232342, 0.35232342, 0.35232342, 0.31468403, 0.27933151,\n",
" 0.24708448, 0.24708448, 0.24708448, 0.24708448, 0.18998087,\n",
" 0.16525956, 0.12395322, 0.12395322, 0.10698086, 0.10698086,\n",
" 0.07864538, 0.06739953, 0.05749692, 0.04911397])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sigmoid(np.dot(X, theta_l)).flatten()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"Collapsed": "false"
},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -4291,7 +4353,7 @@
"4 18.89 norm_2_error_prediction 0.354528"
]
},
"execution_count": 18,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -4316,7 +4378,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 18,
"metadata": {
"Collapsed": "false"
},
Expand Down Expand Up @@ -4840,7 +4902,7 @@
"https://altair-viz.github.io/user_guide/troubleshooting.html\n"
]
},
"execution_count": 19,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -4877,7 +4939,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 19,
"metadata": {
"Collapsed": "false"
},
Expand All @@ -4886,6 +4948,37 @@
"from sklearn.linear_model import LogisticRegression"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"Collapsed": "false"
},
"outputs": [
{
"data": {
"text/plain": [
"LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
" intercept_scaling=1, l1_ratio=None, max_iter=100,\n",
" multi_class='auto', n_jobs=None, penalty='l2',\n",
" random_state=None, solver='lbfgs', tol=0.0001, verbose=0,\n",
" warm_start=False)"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = challenger[[\"temp_c\"]].values\n",
"y = challenger[\"is_failure\"].values\n",
"\n",
"# Fitting the model\n",
"Logit = LogisticRegression(solver=\"lbfgs\")\n",
"Logit.fit(X, y)"
]
},
{
"cell_type": "code",
"execution_count": 21,
Expand All @@ -4902,13 +4995,6 @@
}
],
"source": [
"X = challenger[[\"temp_c\"]]\n",
"y = challenger[\"is_failure\"]\n",
"\n",
"# Fitting the model\n",
"Logit = LogisticRegression(solver=\"lbfgs\")\n",
"Logit.fit(X, y)\n",
"\n",
"# Obtain the coefficients\n",
"print(Logit.intercept_, Logit.coef_ )\n",
"\n",
Expand Down Expand Up @@ -5227,7 +5313,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 30,
"metadata": {
"Collapsed": "false"
},
Expand Down Expand Up @@ -5282,7 +5368,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 31,
"metadata": {
"Collapsed": "false"
},
Expand All @@ -5307,7 +5393,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 32,
"metadata": {
"Collapsed": "false"
},
Expand All @@ -5331,7 +5417,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 33,
"metadata": {
"Collapsed": "false"
},
Expand Down
Loading

0 comments on commit 46ef00a

Please sign in to comment.