Monday, May 13, 2019

Machine Learning Predict Whether Patient Suffer from diabetes

Diabetes Prediction

Machine Learning Model for diabetes Prediction

Introduction:

Diabetes is a disease in which your blood glucose, or blood sugar, levels are too high. Glucose comes from the foods you eat. Insulin is a hormone that helps the glucose get into your cells to give them energy. With type 1 diabetes, your body does not make insulin. With type 2 diabetes, the more common type, your body does not make or use insulin well. Without enough insulin, the glucose stays in your blood. You can also have prediabetes. This means that your blood sugar is higher than normal but not high enough to be called diabetes. Having prediabetes puts you at a higher risk of getting type 2 diabetes.

Over time, having too much glucose in your blood can cause serious problems. It can damage your eyes, kidneys, and nerves. Diabetes can also cause heart disease, stroke and even the need to remove a limb. Pregnant women can also get diabetes, called gestational diabetes.

Blood tests can show if you have diabetes. One type of test, the A1C, can also check on how you are managing your diabetes. Exercise, weight control and sticking to your meal plan can help control your diabetes. You should also monitor your blood glucose level and take medicine if prescribed.

Hence predictiong Diabetes becomes very important. due to advances in machine Learning Algorithm now we can predict whether a patient is likely to get a Diabetes from following parameters

Pregnancies Glucose BloodPressure SkinThickness Insulin BMI DiabetesPedigreeFunction Age Class

Author:

Soumil Nitin Shah,

Bachelor in Electronic Engineering ,

Master in Electrical Engineering ,

Master in Computer Engineering

Full Stack Python Developer

In this article i will show you how you can make a machine learning Model to learn and predict whether the person has Diabetes or not

Accuracy obtained for this project was about 78 %

Part 1 Clean DataSet

Step 1: import Library

In [3]:
import tensorflow as tf
import numpy as np
from sklearn.model_selection import train_test_split
import pandas as pd
import matplotlib.pyplot as plt

%matplotlib inline

Step 2: Read the DataSet

In [5]:
df = pd.read_csv("pima-indians-diabetes.csv")
df.columns
Out[5]:
Index(['6', '148', '72', '35', '0', '33.6', '0.627', '50', '1'], dtype='object')

Step 3 : Rename the column

In [12]:
Col_name = ["Pregnancies","Glucose","BloodPressure",
           "SkinThickness","Insulin","BMI","DiabetesPedigreeFunction",
           "Age","Class"]
In [14]:
df = pd.read_csv("pima-indians-diabetes.csv",header=0,names=Col_name)
df.head(b b3)
Out[14]:
Pregnancies Glucose BloodPressure SkinThickness Insulin BMI DiabetesPedigreeFunction Age Class
0 1 85 66 29 0 26.6 0.351 31 0
1 8 183 64 0 0 23.3 0.672 32 1
2 1 89 66 23 94 28.1 0.167 21 0

Step 4: We need to Normalize the Column so our Machine learning can Predict Diabetes for efficiently !

In [15]:
col_norm =['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin',
       'BMI', 'DiabetesPedigreeFunction']

Step 5: Lets us apply Custom Lambda Function

In [16]:
df1_norm = df[col_norm].apply(lambda x :( (x - x.min()) / (x.max()-x.min()) ) )

Step 6: we have done Normalized the Column

In [17]:
df1_norm.head(3)
Out[17]:
Pregnancies Glucose BloodPressure SkinThickness Insulin BMI DiabetesPedigreeFunction
0 0.058824 0.427136 0.540984 0.292929 0.000000 0.396423 0.116567
1 0.470588 0.919598 0.524590 0.000000 0.000000 0.347243 0.253629
2 0.058824 0.447236 0.540984 0.232323 0.111111 0.418778 0.038002

Part 2 : Prepare Machine Learning Model

Step 1: Create a Feature Column

In [20]:
feat_Pregnancies = tf.feature_column.numeric_column('Pregnancies')

feat_Glucose = tf.feature_column.numeric_column('Glucose')

feat_BloodPressure = tf.feature_column.numeric_column('BloodPressure')

feat_SkinThickness_tricep = tf.feature_column.numeric_column('SkinThickness')

feat_Insulin = tf.feature_column.numeric_column('Insulin')

feat_BMI = tf.feature_column.numeric_column('BMI')

feat_DiabetesPedigreeFunction  = tf.feature_column.numeric_column('DiabetesPedigreeFunction')

We dont have Categorical Column we shall leave that Blank else we would have used Token Bucket Approcah

Step 2: Create a Feature column List

In [21]:
feature_column = [feat_Pregnancies, feat_Glucose, feat_BloodPressure, 
                  feat_SkinThickness_tricep, feat_Insulin, 
                 feat_BMI , feat_DiabetesPedigreeFunction] 

Step 3 :Lets create X_Data and Y_Data

In [25]:
X_Data = df1_norm
X_Data.head(2)
Out[25]:
Pregnancies Glucose BloodPressure SkinThickness Insulin BMI DiabetesPedigreeFunction
0 0.058824 0.427136 0.540984 0.292929 0.0 0.396423 0.116567
1 0.470588 0.919598 0.524590 0.000000 0.0 0.347243 0.253629

Create Y_Data

In [27]:
Y_Data = df["Class"]
Y_Data.head(3)
Out[27]:
0    0
1    1
2    0
Name: Class, dtype: int64

1 = Diabetes and 0 = No Diabetes

In [38]:
X_Train, X_Test, Y_Train, Y_Test = train_test_split(X_Data,Y_Data, test_size=0.3,random_state=101)

Create a Estimator Model

In [39]:
input_func = tf.estimator.inputs.pandas_input_fn(x=X_Train, y=Y_Train,
                                                 batch_size=40,num_epochs =1000, 
                                                 shuffle=True)

LinearClassifier Model

In [40]:
model = tf.estimator.LinearClassifier(feature_columns=feature_column, 
                                      n_classes=2)
INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmp_flaj8c_
INFO:tensorflow:Using config: {'_model_dir': '/var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmp_flaj8c_', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true
graph_options {
  rewrite_options {
    meta_optimizer_iterations: ONE
  }
}
, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x120b435c0>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}

Train Model

In [42]:
model.train(input_fn=input_func, steps = 5000)
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmp_flaj8c_/model.ckpt-2000
WARNING:tensorflow:From /anaconda3/lib/python3.7/site-packages/tensorflow/python/training/saver.py:1070: get_checkpoint_mtimes (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file utilities to get mtimes.
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Saving checkpoints for 2000 into /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmp_flaj8c_/model.ckpt.
INFO:tensorflow:loss = 19.6495, step = 2001
INFO:tensorflow:global_step/sec: 342.301
INFO:tensorflow:loss = 22.423029, step = 2101 (0.294 sec)
INFO:tensorflow:global_step/sec: 484.912
INFO:tensorflow:loss = 18.58068, step = 2201 (0.207 sec)
INFO:tensorflow:global_step/sec: 511.856
INFO:tensorflow:loss = 17.088331, step = 2301 (0.195 sec)
INFO:tensorflow:global_step/sec: 433.725
INFO:tensorflow:loss = 25.449215, step = 2401 (0.230 sec)
INFO:tensorflow:global_step/sec: 461.984
INFO:tensorflow:loss = 18.242695, step = 2501 (0.219 sec)
INFO:tensorflow:global_step/sec: 465.077
INFO:tensorflow:loss = 20.418997, step = 2601 (0.215 sec)
INFO:tensorflow:global_step/sec: 425.795
INFO:tensorflow:loss = 24.720726, step = 2701 (0.234 sec)
INFO:tensorflow:global_step/sec: 487.562
INFO:tensorflow:loss = 17.855951, step = 2801 (0.207 sec)
INFO:tensorflow:global_step/sec: 523.629
INFO:tensorflow:loss = 19.776533, step = 2901 (0.190 sec)
INFO:tensorflow:global_step/sec: 483.744
INFO:tensorflow:loss = 23.198833, step = 3001 (0.210 sec)
INFO:tensorflow:global_step/sec: 374.491
INFO:tensorflow:loss = 21.368155, step = 3101 (0.264 sec)
INFO:tensorflow:global_step/sec: 456.236
INFO:tensorflow:loss = 22.006878, step = 3201 (0.219 sec)
INFO:tensorflow:global_step/sec: 423.166
INFO:tensorflow:loss = 21.266388, step = 3301 (0.235 sec)
INFO:tensorflow:global_step/sec: 304.871
INFO:tensorflow:loss = 17.424366, step = 3401 (0.330 sec)
INFO:tensorflow:global_step/sec: 314.105
INFO:tensorflow:loss = 23.730503, step = 3501 (0.320 sec)
INFO:tensorflow:global_step/sec: 319.567
INFO:tensorflow:loss = 17.441011, step = 3601 (0.316 sec)
INFO:tensorflow:global_step/sec: 320.058
INFO:tensorflow:loss = 17.531582, step = 3701 (0.310 sec)
INFO:tensorflow:global_step/sec: 366.496
INFO:tensorflow:loss = 16.42575, step = 3801 (0.275 sec)
INFO:tensorflow:global_step/sec: 297.467
INFO:tensorflow:loss = 19.441051, step = 3901 (0.336 sec)
INFO:tensorflow:global_step/sec: 356.005
INFO:tensorflow:loss = 20.579514, step = 4001 (0.280 sec)
INFO:tensorflow:global_step/sec: 344.926
INFO:tensorflow:loss = 22.025875, step = 4101 (0.286 sec)
INFO:tensorflow:global_step/sec: 295.437
INFO:tensorflow:loss = 18.309353, step = 4201 (0.340 sec)
INFO:tensorflow:global_step/sec: 371.756
INFO:tensorflow:loss = 17.437687, step = 4301 (0.266 sec)
INFO:tensorflow:global_step/sec: 304.01
INFO:tensorflow:loss = 18.664143, step = 4401 (0.332 sec)
INFO:tensorflow:global_step/sec: 317.459
INFO:tensorflow:loss = 22.34571, step = 4501 (0.318 sec)
INFO:tensorflow:global_step/sec: 324.453
INFO:tensorflow:loss = 15.100108, step = 4601 (0.306 sec)
INFO:tensorflow:global_step/sec: 317.189
INFO:tensorflow:loss = 24.54469, step = 4701 (0.315 sec)
INFO:tensorflow:global_step/sec: 397.771
INFO:tensorflow:loss = 25.05068, step = 4801 (0.247 sec)
INFO:tensorflow:global_step/sec: 348.266
INFO:tensorflow:loss = 19.745575, step = 4901 (0.293 sec)
INFO:tensorflow:global_step/sec: 304.567
INFO:tensorflow:loss = 16.20097, step = 5001 (0.329 sec)
INFO:tensorflow:global_step/sec: 294.872
INFO:tensorflow:loss = 18.254429, step = 5101 (0.339 sec)
INFO:tensorflow:global_step/sec: 436.514
INFO:tensorflow:loss = 22.19273, step = 5201 (0.223 sec)
INFO:tensorflow:global_step/sec: 426.699
INFO:tensorflow:loss = 18.349478, step = 5301 (0.236 sec)
INFO:tensorflow:global_step/sec: 319.28
INFO:tensorflow:loss = 17.701977, step = 5401 (0.311 sec)
INFO:tensorflow:global_step/sec: 315.563
INFO:tensorflow:loss = 15.862208, step = 5501 (0.321 sec)
INFO:tensorflow:global_step/sec: 397.158
INFO:tensorflow:loss = 19.039078, step = 5601 (0.249 sec)
INFO:tensorflow:global_step/sec: 394.176
INFO:tensorflow:loss = 22.82307, step = 5701 (0.252 sec)
INFO:tensorflow:global_step/sec: 426.03
INFO:tensorflow:loss = 16.966248, step = 5801 (0.237 sec)
INFO:tensorflow:global_step/sec: 440.876
INFO:tensorflow:loss = 16.296938, step = 5901 (0.227 sec)
INFO:tensorflow:global_step/sec: 518.672
INFO:tensorflow:loss = 19.302027, step = 6001 (0.192 sec)
INFO:tensorflow:global_step/sec: 531.256
INFO:tensorflow:loss = 18.086044, step = 6101 (0.188 sec)
INFO:tensorflow:global_step/sec: 507.08
INFO:tensorflow:loss = 18.935982, step = 6201 (0.198 sec)
INFO:tensorflow:global_step/sec: 535.603
INFO:tensorflow:loss = 11.872957, step = 6301 (0.186 sec)
INFO:tensorflow:global_step/sec: 537.458
INFO:tensorflow:loss = 14.721358, step = 6401 (0.186 sec)
INFO:tensorflow:global_step/sec: 529.288
INFO:tensorflow:loss = 16.597897, step = 6501 (0.189 sec)
INFO:tensorflow:global_step/sec: 496.995
INFO:tensorflow:loss = 17.572369, step = 6601 (0.198 sec)
INFO:tensorflow:global_step/sec: 370.803
INFO:tensorflow:loss = 19.968132, step = 6701 (0.272 sec)
INFO:tensorflow:global_step/sec: 341.803
INFO:tensorflow:loss = 17.381653, step = 6801 (0.294 sec)
INFO:tensorflow:global_step/sec: 328.867
INFO:tensorflow:loss = 21.950603, step = 6901 (0.307 sec)
INFO:tensorflow:Saving checkpoints for 7000 into /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmp_flaj8c_/model.ckpt.
INFO:tensorflow:Loss for final step: 16.308208.
Out[42]:
<tensorflow_estimator.python.estimator.canned.linear.LinearClassifier at 0x120b433c8>

Loss Drops from 17 to 25

Testing Neural Network on Test Data

Neural Network has Never seen This Data lets See how it Performs

Create Test Estimator

In [43]:
eval_input_func = tf.estimator.inputs.pandas_input_fn(x=X_Test,
                                                      y=Y_Test,
                                                      batch_size=40,
                                                      num_epochs=1,
                                                      shuffle=False)
In [36]:
results = model.evaluate(eval_input_func)
INFO:tensorflow:Calling model_fn.
WARNING:tensorflow:Trapezoidal rule is known to produce incorrect PR-AUCs; please switch to "careful_interpolation" instead.
WARNING:tensorflow:Trapezoidal rule is known to produce incorrect PR-AUCs; please switch to "careful_interpolation" instead.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Starting evaluation at 2019-05-13T14:34:19Z
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmpvhawnncs/model.ckpt-2000
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Finished evaluation at 2019-05-13-14:34:20
INFO:tensorflow:Saving dict for global step 2000: accuracy = 0.7229437, accuracy_baseline = 0.64935064, auc = 0.7661728, auc_precision_recall = 0.64139473, average_loss = 0.55988663, global_step = 2000, label/mean = 0.35064936, loss = 5.388909, precision = 0.70731705, prediction/mean = 0.35670635, recall = 0.3580247
INFO:tensorflow:Saving 'checkpoint_path' summary for global step 2000: /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmpvhawnncs/model.ckpt-2000
In [45]:
results["accuracy"]
Out[45]:
0.7229437

Accuracy is 72 %

Approach 2 Deep Dense Neural Network

In [46]:
dnnmodel = tf.estimator.DNNClassifier(hidden_units=[50,50,50],feature_columns=feature_column,n_classes=2)
INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmpw_lg7hqm
INFO:tensorflow:Using config: {'_model_dir': '/var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmpw_lg7hqm', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true
graph_options {
  rewrite_options {
    meta_optimizer_iterations: ONE
  }
}
, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x1a29d05a20>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}

Create a Estimator API

In [63]:
input_func = tf.estimator.inputs.pandas_input_fn(X_Train, 
                                                 Y_Train,
                                                 batch_size=20,
                                                 num_epochs=2000,
                                                 shuffle=True)

Create DNN Model with 3 Layers 50 Neuron Each

In [64]:
dnnmodel = tf.estimator.DNNClassifier(hidden_units=[30, 30, 30],
                                      feature_columns=feature_column, 
                                      n_classes=2)
INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmputk8cnhj
INFO:tensorflow:Using config: {'_model_dir': '/var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmputk8cnhj', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true
graph_options {
  rewrite_options {
    meta_optimizer_iterations: ONE
  }
}
, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x1a2a135710>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}
In [65]:
dnnmodel.train(input_fn=input_func, 
               steps=2000)
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Saving checkpoints for 0 into /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmputk8cnhj/model.ckpt.
INFO:tensorflow:loss = 13.797264, step = 1
INFO:tensorflow:global_step/sec: 353.173
INFO:tensorflow:loss = 5.1340165, step = 101 (0.284 sec)
INFO:tensorflow:global_step/sec: 367.437
INFO:tensorflow:loss = 10.231861, step = 201 (0.277 sec)
INFO:tensorflow:global_step/sec: 275.679
INFO:tensorflow:loss = 8.70779, step = 301 (0.363 sec)
INFO:tensorflow:global_step/sec: 271.206
INFO:tensorflow:loss = 6.67556, step = 401 (0.365 sec)
INFO:tensorflow:global_step/sec: 333.279
INFO:tensorflow:loss = 8.879939, step = 501 (0.303 sec)
INFO:tensorflow:global_step/sec: 336.824
INFO:tensorflow:loss = 5.390544, step = 601 (0.295 sec)
INFO:tensorflow:global_step/sec: 428.143
INFO:tensorflow:loss = 10.779287, step = 701 (0.233 sec)
INFO:tensorflow:global_step/sec: 357.21
INFO:tensorflow:loss = 4.7543592, step = 801 (0.283 sec)
INFO:tensorflow:global_step/sec: 425.699
INFO:tensorflow:loss = 6.188052, step = 901 (0.238 sec)
INFO:tensorflow:global_step/sec: 389.646
INFO:tensorflow:loss = 5.928564, step = 1001 (0.255 sec)
INFO:tensorflow:global_step/sec: 187.477
INFO:tensorflow:loss = 9.507984, step = 1101 (0.532 sec)
INFO:tensorflow:global_step/sec: 221.937
INFO:tensorflow:loss = 11.523175, step = 1201 (0.448 sec)
INFO:tensorflow:global_step/sec: 410.501
INFO:tensorflow:loss = 8.724625, step = 1301 (0.245 sec)
INFO:tensorflow:global_step/sec: 328.634
INFO:tensorflow:loss = 9.181294, step = 1401 (0.305 sec)
INFO:tensorflow:global_step/sec: 277.881
INFO:tensorflow:loss = 9.71511, step = 1501 (0.359 sec)
INFO:tensorflow:global_step/sec: 408.347
INFO:tensorflow:loss = 5.8519745, step = 1601 (0.244 sec)
INFO:tensorflow:global_step/sec: 376.234
INFO:tensorflow:loss = 6.263546, step = 1701 (0.265 sec)
INFO:tensorflow:global_step/sec: 350.215
INFO:tensorflow:loss = 8.911463, step = 1801 (0.287 sec)
INFO:tensorflow:global_step/sec: 406.522
INFO:tensorflow:loss = 9.780199, step = 1901 (0.246 sec)
INFO:tensorflow:Saving checkpoints for 2000 into /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmputk8cnhj/model.ckpt.
INFO:tensorflow:Loss for final step: 2.7678578.
Out[65]:
<tensorflow_estimator.python.estimator.canned.dnn.DNNClassifier at 0x1a2a1355c0>

Create a Test Function

In [66]:
eveal_input_func = tf.estimator.inputs.pandas_input_fn(x=X_Test,
                                                       y=Y_Test,
                                                       batch_size=20,
                                                       num_epochs=1,
                                                       shuffle=False)
In [67]:
dnnmodel.evaluate(eveal_input_func)
INFO:tensorflow:Calling model_fn.
WARNING:tensorflow:Trapezoidal rule is known to produce incorrect PR-AUCs; please switch to "careful_interpolation" instead.
WARNING:tensorflow:Trapezoidal rule is known to produce incorrect PR-AUCs; please switch to "careful_interpolation" instead.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Starting evaluation at 2019-05-13T14:52:33Z
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmputk8cnhj/model.ckpt-2000
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Finished evaluation at 2019-05-13-14:52:34
INFO:tensorflow:Saving dict for global step 2000: accuracy = 0.77056277, accuracy_baseline = 0.64935064, auc = 0.79971194, auc_precision_recall = 0.6760917, average_loss = 0.52830994, global_step = 2000, label/mean = 0.35064936, loss = 10.169967, precision = 0.73333335, prediction/mean = 0.3230063, recall = 0.54320985
INFO:tensorflow:Saving 'checkpoint_path' summary for global step 2000: /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmputk8cnhj/model.ckpt-2000
Out[67]:
{'accuracy': 0.77056277,
 'accuracy_baseline': 0.64935064,
 'auc': 0.79971194,
 'auc_precision_recall': 0.6760917,
 'average_loss': 0.52830994,
 'label/mean': 0.35064936,
 'loss': 10.169967,
 'precision': 0.73333335,
 'prediction/mean': 0.3230063,
 'recall': 0.54320985,
 'global_step': 2000}
In [68]:
dnnmodel.evaluate(eveal_input_func)["accuracy"]
INFO:tensorflow:Calling model_fn.
WARNING:tensorflow:Trapezoidal rule is known to produce incorrect PR-AUCs; please switch to "careful_interpolation" instead.
WARNING:tensorflow:Trapezoidal rule is known to produce incorrect PR-AUCs; please switch to "careful_interpolation" instead.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Starting evaluation at 2019-05-13T14:52:39Z
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmputk8cnhj/model.ckpt-2000
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Finished evaluation at 2019-05-13-14:52:39
INFO:tensorflow:Saving dict for global step 2000: accuracy = 0.77056277, accuracy_baseline = 0.64935064, auc = 0.79971194, auc_precision_recall = 0.6760917, average_loss = 0.52830994, global_step = 2000, label/mean = 0.35064936, loss = 10.169967, precision = 0.73333335, prediction/mean = 0.3230063, recall = 0.54320985
INFO:tensorflow:Saving 'checkpoint_path' summary for global step 2000: /var/folders/yh/7gktt0ls0fj77fnrs694ht6m0000gn/T/tmputk8cnhj/model.ckpt-2000
Out[68]:
0.77056277

Accuracy is 77 %

3 comments:

How to Use Publish-Audit-Merge Workflow in Apache Iceberg: A Beginner’s Guide

publish How to Use Publish-Audit-Merge Workflow in Apache Iceberg: A Beginner’s Guide ¶ In [24]: from ...