Skip to content

Commit

Permalink
Adding solver='liblinear' in the LogisticRegression, default solver '…
Browse files Browse the repository at this point in the history
…lbfgs' does not support 'l1' penalty.
  • Loading branch information
ken committed Oct 16, 2020
1 parent f000c5b commit 3dd7b35
Showing 1 changed file with 50 additions and 19 deletions.
69 changes: 50 additions & 19 deletions ipython/Labs_Student/Lab_Sklearn_Magic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"In this lab we'll demonstrate several common techniques and helpful tools used in a model building process:\n",
"\n",
Expand All @@ -31,7 +29,10 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand Down Expand Up @@ -81,7 +82,10 @@
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -109,7 +113,10 @@
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand All @@ -125,7 +132,7 @@
"param_grid_lr = {'C':[10**i for i in range(-3, 3)], 'penalty':['l1', 'l2']}\n",
"\n",
"#2nd, call the GridSearchCV class, use LogisticRegression and 'roc_auc' for scoring\n",
"lr_grid_search = GridSearchCV(LogisticRegression(), param_grid_lr, cv = kfolds, scoring = 'roc_auc') \n",
"lr_grid_search = GridSearchCV(LogisticRegression(solver='liblinear'), param_grid_lr, cv = kfolds, scoring = 'roc_auc') \n",
"lr_grid_search.fit(X, Y)\n",
"\n",
"#3rd, get the score of the best model and print it\n",
Expand All @@ -137,7 +144,10 @@
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand Down Expand Up @@ -170,7 +180,10 @@
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand All @@ -190,7 +203,7 @@
"#The last step should be an estimator.\n",
"\n",
"steps = [('scaler', StandardScaler()),\n",
" ('lr', LogisticRegression())]\n",
" ('lr', LogisticRegression(solver='liblinear'))]\n",
"\n",
"#Now set up the pipeline\n",
"pipeline = Pipeline(steps)\n",
Expand All @@ -213,7 +226,10 @@
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand Down Expand Up @@ -246,7 +262,10 @@
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand All @@ -267,7 +286,7 @@
"\n",
"steps_poly = [('polyfeat', PolynomialFeatures()),\n",
" ('scaler', StandardScaler()),\n",
" ('lr', LogisticRegression())]\n",
" ('lr', LogisticRegression(solver='liblinear'))]\n",
"\n",
"#Now set up the pipeline\n",
"pipeline_poly = Pipeline(steps_poly)\n",
Expand All @@ -290,7 +309,10 @@
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand Down Expand Up @@ -327,7 +349,10 @@
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
Expand Down Expand Up @@ -374,7 +399,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": []
Expand All @@ -383,7 +411,10 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
"collapsed": true,
"jupyter": {
"outputs_hidden": true
}
},
"outputs": [],
"source": []
Expand All @@ -406,9 +437,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 4
}

0 comments on commit 3dd7b35

Please sign in to comment.