<jupyter_start><jupyter_text>Making Predictions<jupyter_code># Make Predictions
P = model.predict(X_test)
print(P) # they are outputs of the sigmoid, interpretted as probabilities (py=1|x)
# Round to get the actual Predictions
# Note! has to be flattened since the targtets are size(N,) while the predictions ar3e size (N,1)
import numpy as np
P = np.round(P).flatten()
print(P)
# Calculate the accuracy, compare it to evaluate() output
print('Manuallty calculated accuracy:', np.mean(P==y_test))
print('Evaluate output:', model.evaluate(X_test, y_test))<jupyter_output>Manuallty calculated accuracy: 0.973404255319149

188/1 [===============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================[...]<jupyter_text>Part3: Saving and Loading the Model<jupyter_code># Let's now save our model to a file
model.save('linearclassifier.h5')
# check that the model exists
!ls -lh
# Let's load the model and confirm that it still works
# note! there is a bug in Keras where load/save only works if you DONT use the Input() layer explicitly
# make sure you define the model with only Dense(1, Input_shape=(D,))
model = tf.keras.models.load_model('linearclassifier.h5')
print(model.layers)
model.evaluate(X_test,y_test)
# Download the file - requires Google Chrome
from google.colab import files
files.download('linearclassifier.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.4831612034126628, 'fraction_numerical': 0.012572968118545127, 'mean_word_length': 11.377777777777778, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '380835', 'license': 'MIT', 'n_tokens_mistral': 503, 'n_tokens_neox': 433, 'n_words': 142, 'path': 'TF2.0_Linear_Classification_v2.ipynb', 'repo_name': 'adasrinivas1229/AI_AND_DL_TF2_ALL', 'size': '2227'}