ium_452487/validate.ipynb

205 lines
6.1 KiB
Plaintext
Raw Normal View History

2024-04-14 17:30:10 +02:00
{
"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 566us/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
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}