Skip to content

Commit

Permalink
Chapter 05 section 08 completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyubobobo committed Dec 9, 2017
1 parent 530e737 commit b0fc6a0
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 08 scikit-learn 中的 Linear Regression"
"## 08 实现我们自己的 Linear Regression"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 09 kNN Regressor 解决回归问题"
"## 09 scikit-learn中的回归问题"
]
},
{
Expand Down Expand Up @@ -70,9 +70,16 @@
"X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### scikit-learn中的线性回归"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -81,7 +88,7 @@
"LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)"
]
},
"execution_count": 9,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -95,7 +102,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -108,7 +115,7 @@
" -3.99667727e-01])"
]
},
"execution_count": 10,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -119,7 +126,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -128,7 +135,7 @@
"32.645660839653587"
]
},
"execution_count": 11,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -139,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -148,7 +155,7 @@
"0.80089161995191116"
]
},
"execution_count": 12,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -166,31 +173,31 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.6319037967897394"
"0.60267450508095299"
]
},
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn.neighbors import KNeighborsRegressor\n",
"\n",
"knn_reg = KNeighborsRegressor(n_neighbors=3)\n",
"knn_reg = KNeighborsRegressor()\n",
"knn_reg.fit(X_train, y_train)\n",
"knn_reg.score(X_test, y_test)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -204,7 +211,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"[Parallel(n_jobs=-1)]: Done 180 out of 180 | elapsed: 1.1s finished\n"
"[Parallel(n_jobs=-1)]: Done 180 out of 180 | elapsed: 1.3s finished\n"
]
},
{
Expand All @@ -220,7 +227,7 @@
" scoring=None, verbose=1)"
]
},
"execution_count": 15,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -247,7 +254,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -256,7 +263,7 @@
"{'n_neighbors': 3, 'p': 1, 'weights': 'uniform'}"
]
},
"execution_count": 17,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -267,7 +274,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand All @@ -276,14 +283,34 @@
"0.57325417167989967"
]
},
"execution_count": 18,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grid_search.best_score_"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.73394216830389403"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"grid_search.best_estimator_.score(X_test, y_test)"
]
}
],
"metadata": {
Expand Down
Binary file modified 05-Linear-Regression/Chapter-05.key
Binary file not shown.

0 comments on commit b0fc6a0

Please sign in to comment.