Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
campusx-official authored Jun 12, 2021
1 parent 88e322e commit 8c8e5fe
Showing 1 changed file with 166 additions and 0 deletions.
166 changes: 166 additions & 0 deletions day57-elasticnet-regression/elastic-net-regression.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 70,
"id": "71e28874",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.datasets import load_diabetes\n",
"from sklearn.linear_model import LinearRegression,Ridge,Lasso,ElasticNet\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.metrics import r2_score"
]
},
{
"cell_type": "code",
"execution_count": 71,
"id": "284ccf3c",
"metadata": {},
"outputs": [],
"source": [
"X,y = load_diabetes(return_X_y=True)"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "799d9080",
"metadata": {},
"outputs": [],
"source": [
"X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "8a242b9f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.4399387660024645"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Linear Regression\n",
"reg = LinearRegression()\n",
"reg.fit(X_train,y_train)\n",
"y_pred = reg.predict(X_test)\n",
"r2_score(y_test,y_pred)"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "a41eb10c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.4519973816947852"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Ridge \n",
"reg = Ridge(alpha=0.1)\n",
"reg.fit(X_train,y_train)\n",
"y_pred = reg.predict(X_test)\n",
"r2_score(y_test,y_pred)"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "b6b53e7c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.4411227990495632"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Lasso\n",
"reg = Lasso(alpha=0.01)\n",
"reg.fit(X_train,y_train)\n",
"y_pred = reg.predict(X_test)\n",
"r2_score(y_test,y_pred)"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "5fc65b12",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.4531493801165679"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# ElasticNet\n",
"reg = ElasticNet(alpha=0.005,l1_ratio=0.9)\n",
"reg.fit(X_train,y_train)\n",
"y_pred = reg.predict(X_test)\n",
"r2_score(y_test,y_pred)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0cb67b0c",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 8c8e5fe

Please sign in to comment.