<jupyter_start><jupyter_text>Load Compressed Test-data files<jupyter_code>import numpy as np
import argparse
import os
import joblib
import gzip
import struct


# load compressed MNIST gz files and return numpy arrays
def load_data(filename, label=False):
    with gzip.open(filename) as gz:
        struct.unpack('I', gz.read(4))
        n_items = struct.unpack('>I', gz.read(4))
        if not label:
            n_rows = struct.unpack('>I', gz.read(4))[0]
            n_cols = struct.unpack('>I', gz.read(4))[0]
            res = np.frombuffer(gz.read(n_items[0] * n_rows * n_cols), dtype=np.uint8)
            res = res.reshape(n_items[0], n_rows * n_cols)
        else:
            res = np.frombuffer(gz.read(n_items[0]), dtype=np.uint8)
            res = res.reshape(n_items[0], 1)
    return res


data_folder = os.path.join(os.getcwd(), 'data/mnist')

# load train and test set into numpy arrays
# note we scale the pixel intensity values to 0-1 (by dividing it with 255.0) so the model can converge faster.
X_test = load_data("{}/t10k-images-idx3-ubyte.gz".format(data_folder), False) / 255.0
y_test = load_data("{}/t10k-labels-idx1-ubyte.gz".format(data_folder), True).reshape(-1)
print("X_test Shape: {}\ny_test Shape: {}".format(X_test.shape, y_test.shape))

clf = joblib.load('sklearn_mnist_model.pkl')

print('Predict the test set')
y_pred = clf.predict(X_test)

# calculate accuracy on the prediction
acc = np.average(y_pred == y_test)
print('Accuracy is', acc)

np.savetxt("y_test_predicted.csv", y_pred, delimiter=",")<jupyter_output>Predict the test set
Accuracy is 0.9193
{'fraction_non_alphanumeric': 0.13953488372093023, 'fraction_numerical': 0.02199874292897549, 'mean_word_length': 3.7951807228915664, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '365279', 'license': 'Apache-2.0', 'n_tokens_mistral': 614, 'n_tokens_neox': 587, 'n_words': 137, 'path': 'Model Test.ipynb', 'repo_name': 'rujual/KServe-Mnist-demo', 'size': '1591'}