{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "5600f60e", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import time\n", "import gc\n", "import random\n", "from sklearn.model_selection import cross_val_score, GridSearchCV, cross_validate, train_test_split\n", "from sklearn.metrics import accuracy_score, classification_report\n", "from sklearn.svm import SVC\n", "from sklearn.linear_model import LinearRegression\n", "from sklearn.neural_network import MLPClassifier\n", "from sklearn.ensemble import RandomForestClassifier\n", "from sklearn.preprocessing import StandardScaler, normalize\n", "from sklearn.decomposition import PCA\n", "from sklearn.impute import SimpleImputer\n", "\n", "df = pd.read_csv(\"data/pima-indians-diabetes.csv\")" ] }, { "cell_type": "code", "execution_count": 2, "id": "ba9ed7e8", "metadata": {}, "outputs": [], "source": [ "x_data = df.filter(regex='x\\d')\n", "y_data = df.filter(regex='y')" ] }, { "cell_type": "code", "execution_count": 3, "id": "4e150ff2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
y
01
10
21
30
41
......
7630
7640
7650
7661
7670
\n", "

768 rows × 1 columns

\n", "
" ], "text/plain": [ " y\n", "0 1\n", "1 0\n", "2 1\n", "3 0\n", "4 1\n", ".. ..\n", "763 0\n", "764 0\n", "765 0\n", "766 1\n", "767 0\n", "\n", "[768 rows x 1 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y_data" ] }, { "cell_type": "code", "execution_count": 4, "id": "e2870990", "metadata": {}, "outputs": [], "source": [ "x_train, x_test, y_train, y_test = train_test_split(x_data, y_data, train_size=0.7,test_size=0.3, random_state= 614, shuffle = True)" ] }, { "cell_type": "code", "execution_count": 6, "id": "9b3459f7", "metadata": {}, "outputs": [], "source": [ "linear_regression_classifier = LinearRegression().fit(x_train, y_train)\n", "y_predict_train = linear_regression_classifier.predict(x_train)\n", "y_predict_test = linear_regression_classifier.predict(x_test)" ] }, { "cell_type": "code", "execution_count": 15, "id": "d57b40fb", "metadata": {}, "outputs": [], "source": [ "y_predict_train = [i.round() for i in y_predict_train]\n", "train_accuracy = accuracy_score(y_train,y_predict_train)" ] }, { "cell_type": "code", "execution_count": 14, "id": "af7edfc2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.7821229050279329" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_accuracy" ] }, { "cell_type": "code", "execution_count": 16, "id": "4209f55e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.7821229050279329" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_accuracy" ] }, { "cell_type": "code", "execution_count": null, "id": "682449cc", "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.7.3" } }, "nbformat": 4, "nbformat_minor": 5 }