Created
October 9, 2018 02:15
-
-
Save ClebsonDantasUchoa/3c67ec90ad021a0c2b418fe7ae108391 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": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd\n", | |
"import numpy as np\n", | |
"from sklearn import linear_model\n", | |
"from sklearn import metrics\n", | |
"from sklearn import model_selection\n", | |
"import math" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"data = pd.read_csv(\"train.csv\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"X = data[[\"NU_NOTA_CN\"]].fillna(0) \n", | |
"y = data[\"NU_NOTA_MT\"].fillna(0)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"58.05735426311826\n" | |
] | |
} | |
], | |
"source": [ | |
"X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, random_state=1)\n", | |
"linreg = linear_model.LinearRegression()\n", | |
"linreg.fit(X_train, y_train)\n", | |
"result = linreg.predict(X_test)\n", | |
"print(metrics.mean_absolute_error(y_test, result))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"9642.803695664637\n", | |
"98.19777846603577\n" | |
] | |
} | |
], | |
"source": [ | |
"print(metrics.mean_squared_error(y_test, result))\n", | |
"print(math.sqrt(metrics.mean_squared_error(y_test, result)))" | |
] | |
}, | |
{ | |
"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.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment