Newer
Older
" SOCKEYE ONLY : best_score = -2.95\n",
"BOTH COMBINED : average_score = -4.19\n",
"\n",
"DecisionTreeRegressor(criterion='mse', max_depth=None, max_features=None,\n",
" max_leaf_nodes=None, min_impurity_decrease=0.0,\n",
" min_impurity_split=None, min_samples_leaf=1,\n",
" min_samples_split=2, min_weight_fraction_leaf=0.0,\n",
" presort=False, random_state=None, splitter='best')\n",
"ONE MODEL : best_score = -4.60\n",
" ATLANTIC ONLY : best_score = -5.52\n",
" SOCKEYE ONLY : best_score = -2.98\n",
"BOTH COMBINED : average_score = -4.25\n",
"\n",
"KernelRidge(alpha=1, coef0=1, degree=3, gamma=None, kernel='linear',\n",
" kernel_params=None)\n",
"ONE MODEL : best_score = -4.52\n",
" ATLANTIC ONLY : best_score = -5.63\n",
" SOCKEYE ONLY : best_score = -3.08\n",
"BOTH COMBINED : average_score = -4.35\n",
"\n",
"KernelRidge(alpha=1, coef0=1, degree=3, gamma=None, kernel='rbf',\n",
" kernel_params=None)\n",
"ONE MODEL : best_score = -4.57\n",
" ATLANTIC ONLY : best_score = -5.89\n",
" SOCKEYE ONLY : best_score = -3.18\n",
"BOTH COMBINED : average_score = -4.54\n",
"\n",
"SVR(C=1.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.1,\n",
" gamma='auto_deprecated', kernel='rbf', max_iter=-1, shrinking=True,\n",
" tol=0.001, verbose=False)\n",
"ONE MODEL : best_score = -4.38\n",
" ATLANTIC ONLY : best_score = -5.56\n",
" SOCKEYE ONLY : best_score = -3.13\n",
"BOTH COMBINED : average_score = -4.35\n",
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
]
}
],
"source": [
"from sklearn.pipeline import make_pipeline\n",
"from sklearn.preprocessing import StandardScaler, PolynomialFeatures\n",
"from sklearn.kernel_ridge import KernelRidge\n",
"from sklearn.linear_model import LinearRegression\n",
"from sklearn.svm import SVR\n",
"from sklearn.tree import DecisionTreeRegressor \n",
"from sklearn.model_selection import cross_val_score\n",
"from sklearn.decomposition import PCA\n",
"\n",
"\n",
"sockey_indices = features[\"kind\"] == 1\n",
"features_sockeye = features[sockey_indices]\n",
"values_sockeye = values[sockey_indices]\n",
"\n",
"atlantic_indices = features[\"kind\"] == 0\n",
"features_atlantic = features[atlantic_indices]\n",
"values_atlantic = values[atlantic_indices]\n",
"\n",
"\n",
"def eval_clf(clf):\n",
" print(clf)\n",
" p = make_pipeline(PolynomialFeatures(), PCA(), DecisionTreeRegressor())\n",
"\n",
" param_grid = {'polynomialfeatures__degree': range(3, 12),\n",
" 'pca__n_components': range(1, 10),\n",
" }\n",
"\n",
" search = GridSearchCV(p, param_grid, scoring=\"neg_mean_absolute_error\", cv=4, n_jobs=4)\n",
" print(\"ONE MODEL : best_score = {:.2f}\".format(search.best_score_))\n",
" score_full = search.best_score_\n",
"\n",
" search.fit(features_atlantic, values_atlantic)\n",
" print(\" ATLANTIC ONLY : best_score = {:.2f}\".format(search.best_score_))\n",
" score_atlantic = search.best_score_\n",
"\n",
" search.fit(features_sockeye, values_sockeye)\n",
" print(\" SOCKEYE ONLY : best_score = {:.2f}\".format(search.best_score_))\n",
" print(\"BOTH COMBINED : average_score = {:.2f}\".format((score_atlantic + score_sockeye) / 2.0))\n",
" print()\n",
" \n",
" \n",
"eval_clf(LinearRegression())\n",
"eval_clf(DecisionTreeRegressor())\n",
"eval_clf(KernelRidge())\n",
"eval_clf(KernelRidge(kernel=\"rbf\"))\n",
"eval_clf(SVR())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}