Created
August 20, 2018 14:59
-
-
Save mindaslab/367cd40c39ea1341ed01ff12049fdd3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"This is for this https://towardsdatascience.com/introduction-to-machine-learning-algorithms-linear-regression-14c4e325882a article " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"from sklearn.linear_model import LinearRegression \n", | |
"from sklearn.metrics import r2_score" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"df_train = pd.read_csv('train.csv')\n", | |
"df_test = pd.read_csv('test.csv')\n", | |
"\n", | |
"df_train.dropna(inplace=True)\n", | |
"\n", | |
"x_train = df_train['x']\n", | |
"y_train = df_train['y']\n", | |
"x_test = df_test['x']\n", | |
"y_test = df_test['y']\n", | |
"\n", | |
"x_train = np.array(x_train)\n", | |
"y_train = np.array(y_train)\n", | |
"x_test = np.array(x_test)\n", | |
"y_test = np.array(y_test)\n", | |
"\n", | |
"x_train = x_train.reshape(-1,1)\n", | |
"x_test = x_test.reshape(-1,1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0.9889654279220864\n" | |
] | |
} | |
], | |
"source": [ | |
"clf = LinearRegression(normalize=True)\n", | |
"clf.fit(x_train,y_train)\n", | |
"y_pred = clf.predict(x_test)\n", | |
"print(r2_score(y_test,y_pred))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"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.6.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment