Solution for Scikit-learn
\n",
" \n",
"\n",
"clf = skLogistic()\n",
"clf.fit(X_train.get(), y_train.get())\n",
"clf.score(X_test.get(), y_test.get())\n",
"
\n",
" \n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import accuracy_score"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Solution for CuML
\n",
" \n",
"\n",
"reg = LogisticRegression()\n",
"reg.fit(X_train,y_train)\n",
"\n",
"print(\"Coefficients:\")\n",
"print(reg.coef_)\n",
"print(\"Intercept:\")\n",
"print(reg.intercept_)\n",
"\n",
"preds = reg.predict(X_test)\n",
"\n",
"print(preds)\n",
"\n",
"print('Scikit-learn accuracy: ' + str(reg.score(X_test, y_test)))\n",
"
\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"from cuml import LogisticRegression\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Coefficients:\n",
"[[-1.28726705]\n",
" [ 2.75051631]]\n",
"Intercept:\n",
"[-0.812162]\n",
"Scikit-learn accuracy: 0.8025000095367432\n"
]
}
],
"source": [
"# useful methods: cupy_array.astype(np_dtype) converts an array from one datatype to np_datatype, where np_datatype can be something like np.float32, np.float64, etc.\n",
"# useful methods: cudf_seris.to_array() converts a cuDF Series to a numpy array\n",
"# useful methods: cp.asnumpy(cupy_array) converts cupy to numpy\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Expected accuracies for apples to apples comparison: 0.8025 vs 0.8695**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Additional Exercise: Play with the different parameters, particularly the different Scikit-learn solvers to see how they differ in behavior even in the same library!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Licensing\n",
" \n",
"This material is released by OpenACC-Standard.org, in collaboration with NVIDIA Corporation, under the Creative Commons Attribution 4.0 International (CC BY 4.0)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[1]]()\n",
"[[2]]()\n",
"[[3]]()\n",
"[[4]]()\n",
"[[5]]()"
]
}
],
"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.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}