You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.5 KiB
133 lines
3.5 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4c285a8e",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Welcome to the world of Machine Learning"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "471131ae",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"[1 2 3 4]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"a = np.array([[1, 2, 3, 4], [ 5, 6, 7, 8], [9, 10, 11, 12]])\n",
|
|
"print(a[0])\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"id": "483bcfdb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import numpy as np\n",
|
|
"from sklearn import datasets, linear_model, model_selection\n",
|
|
"import pandas as pd\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"id": "6ffd05a8",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"(442, 10)\n",
|
|
"[ 0.03807591 0.05068012 0.06169621 0.02187239 -0.0442235 -0.03482076\n",
|
|
" -0.04340085 -0.00259226 0.01990749 -0.01764613]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"x, y = datasets.load_diabetes(return_X_y=True)\n",
|
|
"print(x.shape)\n",
|
|
"print(x[0])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "b7d5a1b8",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "IndexError",
|
|
"evalue": "index 2 is out of bounds for axis 1 with size 1",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
|
"\u001b[31mIndexError\u001b[39m Traceback (most recent call last)",
|
|
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[28]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m x = \u001b[43mx\u001b[49m\u001b[43m[\u001b[49m\u001b[43m:\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m2\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[32m 2\u001b[39m x = x.reshape((-\u001b[32m1\u001b[39m,\u001b[32m1\u001b[39m))\n\u001b[32m 3\u001b[39m x_train, x_test, y_train, y_test = model_selection.train_test_split(x, y, test_size=\u001b[32m0.33\u001b[39m)\n",
|
|
"\u001b[31mIndexError\u001b[39m: index 2 is out of bounds for axis 1 with size 1"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"x = x[:, 2]\n",
|
|
"x = x.reshape((-1,1))\n",
|
|
"x_train, x_test, y_train, y_test = model_selection.train_test_split(x, y, test_size=0.33)\n",
|
|
"model = linear_model.LinearRegression()\n",
|
|
"model.fit(x_train, y_train)\n",
|
|
"y_pred =model.predict(x_test)\n",
|
|
"plt.scatter(x_test, y_test, color='black')\n",
|
|
"plt.plot(x_test, y_pred, color='blue', linewidth=3)\n",
|
|
"plt.xlabel('Scaled BMI')\n",
|
|
"plt.ylabel('Diabetes Progression')\n",
|
|
"plt.title('A graph plot showng Diabetes Progression Against Scaled BMI') \n",
|
|
"plt.show()\n",
|
|
"# end"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f3b27b8d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".venv",
|
|
"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.13.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|