{ "cells": [ { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "import zipfile\n", "with zipfile.ZipFile(\"dataset_cleaned.zip\", 'r') as zip_ref:\n", " zip_ref.extractall(\"dataset_cleaned_extracted\")" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 1, "outputs": [], "source": [ "import pandas as pd\n", "valid = pd.read_csv(\"dataset_cleaned_extracted/valid.csv\")\n", "\n", "x_columns = ['Male', 'GeneralHealth', 'PhysicalHealthDays', 'MentalHealthDays',\n", " 'PhysicalActivities', 'SleepHours', 'RemovedTeeth',\n", " 'HadAngina', 'HadStroke', 'HadAsthma', 'HadSkinCancer', 'HadCOPD',\n", " 'HadDepressiveDisorder', 'HadKidneyDisease', 'HadArthritis',\n", " 'HadDiabetes', 'DeafOrHardOfHearing', 'BlindOrVisionDifficulty',\n", " 'DifficultyConcentrating', 'DifficultyWalking',\n", " 'DifficultyDressingBathing', 'DifficultyErrands', 'SmokerStatus',\n", " 'ECigaretteUsage', 'ChestScan', 'HeightInMeters', 'WeightInKilograms',\n", " 'BMI', 'AlcoholDrinkers', 'HIVTesting', 'FluVaxLast12', 'PneumoVaxEver',\n", " 'TetanusLast10Tdap', 'HighRiskLastYear', 'CovidPos']\n", "y_column = 'HadHeartAttack'\n", "\n", "valid_x = valid[x_columns]\n", "valid_y = valid[y_column]" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 2, "outputs": [], "source": [ "from tensorflow import keras\n", "model = keras.models.load_model('model_v1.keras')" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 3, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1392/1392 [==============================] - 1s 645us/step\n", "Poprawność na zbiorze walidacyjnym: 86.15%\n" ] } ], "source": [ "import numpy as np\n", "predictions = model.predict(valid_x)[:,0]\n", "true_answers = valid_y.to_numpy()\n", "validation_accuracy = np.sum(np.rint(predictions) == true_answers)/len(true_answers)\n", "print(f\"Poprawność na zbiorze walidacyjnym: {validation_accuracy:.2%}\")" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 4, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0.08692811 0.12067404 0.31880796 0.64843357 0.15188715 0.06517262\n", " 0.03407578 0.49311596 0.00781232 0.2089161 0.46056542 0.45341685\n", " 0.4294767 0.25619727 0.20345858 0.2302334 0.38631877 0.36519188\n", " 0.04014764 0.23888215 0.27519897 0.08928084 0.05204074 0.42043713\n", " 0.19055638 0.29787344 0.23068897 0.88435644 0.03139259 0.95048493\n", " 0.2457671 0.5858893 0.02678488 0.06240147 0.52132165 0.01431455\n", " 0.02444405 0.07804424 0.11274771 0.12714393 0.35450152 0.01294624\n", " 0.190797 0.07512036 0.48486376 0.06140704 0.9019506 0.08810509\n", " 0.61831665 0.15642735 0.03310075 0.04532438 0.10763614 0.4277772\n", " 0.20325996 0.8980398 0.7491019 0.38502344 0.03970775 0.0401529\n", " 0.03046079 0.10123587 0.04993626 0.05702 0.18049946 0.1223311\n", " 0.731555 0.40104443 0.18443953 0.1265702 0.07467585 0.03895461\n", " 0.35271063 0.38039213 0.4450048 0.03670818 0.05534125 0.91664517\n", " 0.413391 0.12545326 0.11306539 0.4350903 0.48778924 0.40804324\n", " 0.33885244 0.21948677 0.01242744 0.02531701 0.6693964 0.15393472\n", " 0.9307252 0.09181138 0.05571133 0.1261858 0.02687709 0.27069062\n", " 0.22613294 0.20686075 0.47390068 0.40349996]\n" ] } ], "source": [ "print(predictions[:100])" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 5, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 0. 0. 1. 0. 1. 0. 1. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0.\n", " 1. 0. 0. 0. 0. 0. 0. 1. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.\n", " 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 1. 0. 0. 0. 0. 0.\n", " 0. 0. 0. 0.]\n" ] } ], "source": [ "print(np.rint(predictions)[:100])" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 6, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", " 0. 1. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0.\n", " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0.\n", " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.\n", " 0. 0. 0. 0.]\n" ] } ], "source": [ "print(true_answers[:100])" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 7, "outputs": [], "source": [ "np.savetxt(\"predictions.txt\",predictions)" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 8, "outputs": [], "source": [ "np.savetxt(\"predictions_two_digits.txt\",predictions, fmt='%1.2f')" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 9, "outputs": [ { "data": { "text/plain": " Unnamed: 0 State Male GeneralHealth PhysicalHealthDays \\\n7 135450 Kentucky 1.0 0.50 0.0 \n25 321301 Rhode Island 1.0 0.00 1.0 \n29 402512 Washington 1.0 0.25 0.0 \n44 128060 Kansas 1.0 0.50 0.0 \n69 130420 Kansas 1.0 0.75 0.0 \n\n MentalHealthDays LastCheckupTime \\\n7 0.0 Within past year (anytime less than 12 months ... \n25 1.0 Within past year (anytime less than 12 months ... \n29 0.1 Within past year (anytime less than 12 months ... \n44 0.0 Within past year (anytime less than 12 months ... \n69 0.0 5 or more years ago \n\n PhysicalActivities SleepHours RemovedTeeth ... HeightInMeters \\\n7 1.0 0.260870 1.000000 ... 0.613793 \n25 1.0 0.260870 0.000000 ... 0.634483 \n29 1.0 0.347826 0.333333 ... 0.510345 \n44 0.0 0.260870 0.333333 ... 0.455172 \n69 1.0 0.217391 0.333333 ... 0.544828 \n\n WeightInKilograms BMI AlcoholDrinkers HIVTesting FluVaxLast12 \\\n7 0.164353 0.095584 1.0 0.0 0.0 \n25 0.193760 0.116415 1.0 0.0 0.0 \n29 0.380616 0.389716 1.0 0.0 1.0 \n44 0.084789 0.203190 1.0 0.0 1.0 \n69 0.190289 0.153196 1.0 0.0 0.0 \n\n PneumoVaxEver TetanusLast10Tdap HighRiskLastYear CovidPos \n7 0.0 0.0 0.0 0.0 \n25 0.0 0.0 0.0 0.0 \n29 1.0 0.0 1.0 0.0 \n44 1.0 0.0 0.0 0.0 \n69 0.0 0.0 0.0 0.0 \n\n[5 rows x 41 columns]", "text/html": "
\n | Unnamed: 0 | \nState | \nMale | \nGeneralHealth | \nPhysicalHealthDays | \nMentalHealthDays | \nLastCheckupTime | \nPhysicalActivities | \nSleepHours | \nRemovedTeeth | \n... | \nHeightInMeters | \nWeightInKilograms | \nBMI | \nAlcoholDrinkers | \nHIVTesting | \nFluVaxLast12 | \nPneumoVaxEver | \nTetanusLast10Tdap | \nHighRiskLastYear | \nCovidPos | \n
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7 | \n135450 | \nKentucky | \n1.0 | \n0.50 | \n0.0 | \n0.0 | \nWithin past year (anytime less than 12 months ... | \n1.0 | \n0.260870 | \n1.000000 | \n... | \n0.613793 | \n0.164353 | \n0.095584 | \n1.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n
25 | \n321301 | \nRhode Island | \n1.0 | \n0.00 | \n1.0 | \n1.0 | \nWithin past year (anytime less than 12 months ... | \n1.0 | \n0.260870 | \n0.000000 | \n... | \n0.634483 | \n0.193760 | \n0.116415 | \n1.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n
29 | \n402512 | \nWashington | \n1.0 | \n0.25 | \n0.0 | \n0.1 | \nWithin past year (anytime less than 12 months ... | \n1.0 | \n0.347826 | \n0.333333 | \n... | \n0.510345 | \n0.380616 | \n0.389716 | \n1.0 | \n0.0 | \n1.0 | \n1.0 | \n0.0 | \n1.0 | \n0.0 | \n
44 | \n128060 | \nKansas | \n1.0 | \n0.50 | \n0.0 | \n0.0 | \nWithin past year (anytime less than 12 months ... | \n0.0 | \n0.260870 | \n0.333333 | \n... | \n0.455172 | \n0.084789 | \n0.203190 | \n1.0 | \n0.0 | \n1.0 | \n1.0 | \n0.0 | \n0.0 | \n0.0 | \n
69 | \n130420 | \nKansas | \n1.0 | \n0.75 | \n0.0 | \n0.0 | \n5 or more years ago | \n1.0 | \n0.217391 | \n0.333333 | \n... | \n0.544828 | \n0.190289 | \n0.153196 | \n1.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n0.0 | \n
5 rows × 41 columns
\n