<jupyter_start><jupyter_text>Min-Max Scaling:$X'=a+{\frac {\left(X-X_{\min }\right)\left(b-a\right)}{X_{\max }-X_{\min }}}$<jupyter_code># normalize data
is_features_normal = False
is_labels_encod = False
amin = 0.1
bmax = 0.9

def normalize_data(image_data, amin, bmax):
    image_data = np.array(image_data)
    return amin + (image_data - np.min(image_data))*(bmax - amin) / (np.max(image_data) - np.min(image_data))

# Test Cases
np.testing.assert_array_almost_equal(
    normalize_data(np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 255]), 0.1, 0.9),
    [0.1, 0.103137254902, 0.106274509804, 0.109411764706, 0.112549019608, 0.11568627451, 0.118823529412, 0.121960784314,
     0.125098039216, 0.128235294118, 0.13137254902, 0.9],
    decimal=3)
print('Tests Passed!')
if not is_features_normal:
    train_features = normalize_data(train_features, amin, bmax)
    test_features = normalize_data(test_features, amin, bmax)
    is_features_normal = True

if not is_labels_encod:
    encoder = LabelBinarizer()
    encoder.fit(train_labels)
    print(encoder.classes_)
    train_labels = encoder.transform(train_labels)
    test_labels = encoder.transform(test_labels)
    
    train_labels = train_labels.astype(np.float32)
    test_labels = test_labels.astype(np.float32)
    is_label_encod = True
print('Labels One-Hot Encoded')
# split train and validate data set
train_features, valid_features, train_labels, valid_labels = train_test_split(
    train_features, train_labels, test_size=0.05, random_state=832289)

print('Training features and labels randomized and split.')
# save the data for easy access
pickle_file = 'notMNIST.pickle'
if not os.path.isfile(pickle_file):
    print('Saving data to pickle file...')
    try:
        with open(pickle_file, 'wb') as pfile:
            pickle.dump({
                    'train_dataset': train_features,
                    'train_labels': train_labels,
                    'valid_dataset': valid_features,
                    'valid_labels': valid_labels,
                    'test_dataset': test_features,
                    'test_labels': test_labels,
                }, pfile, pickle.HIGHEST_PROTOCOL)
    except Exception as e:
        print('Unable to save data to ', pickle_file, ':', e )
        raise
print('Data cached in pickle file')<jupyter_output>Saving data to pickle file...
Data cached in pickle file
{'fraction_non_alphanumeric': 0.11692697340650063, 'fraction_numerical': 0.07133811734909244, 'mean_word_length': 3.438202247191011, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '203088', 'license': 'MIT', 'n_tokens_mistral': 942, 'n_tokens_neox': 807, 'n_words': 179, 'path': 'practice/intro-tensorflow/deepnn 1 - data preprocessing.ipynb', 'repo_name': 'iratao/deep-learning', 'size': '2369'}