<jupyter_start><jupyter_text>Importing the MNIST Dataset to perform Multi-Class Classification. MNIST is a large database of handwritten digits that is commonly used for training various image processing systems.[More Information in Wikipedia](https://en.wikipedia.org/wiki/MNIST_database)<jupyter_code>from sklearn.datasets import fetch_openml
X, y = fetch_openml('mnist_784', return_X_y=True)<jupyter_output><empty_output><jupyter_text>Shape of the dataset<jupyter_code>X.shape<jupyter_output><empty_output><jupyter_text>Visualizing the first 5 images in the datasetWe are reshaping the each array as a 28X28 Image so that we can plot it<jupyter_code>import matplotlib.pyplot as plt
for i in range(5):
    plt.imshow(X[i].reshape((28,28)))
    plt.show()<jupyter_output><empty_output><jupyter_text>Importing the Logistic Regression Model from Scikit-Learn and Data Processing1. We are decreasing the size of the dataset for training.2. Then, we scale the data.3. Finally, we split the dataset into training and test sets<jupyter_code>from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn import preprocessing

# STEP 1
X, y = X[:10_000], y[:10_000]

# STEP 2
X_scaled = preprocessing.scale(X)

# STEP 3
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, random_state = 42)<jupyter_output><empty_output><jupyter_text>Then, we finally train the Logistic Regression Model.<jupyter_code>model = LogisticRegression(random_state=0, max_iter=2000)
model.fit(X_train, y_train)
print("Model Training Completed!")<jupyter_output>Model Training Completed!<jupyter_text>We now measuring the accuracy score of the model that we have trained.<jupyter_code>from sklearn.metrics import accuracy_score
preds = model.predict(X_test)
score = accuracy_score(y_test, preds) 
print(f"Model's accuracy score is : {round(score*100, 2)} %")<jupyter_output>Model's accuracy score is : 89.76 %<jupyter_text>Demonstrating the model's predictions on one of the image from our test-set.<jupyter_code>pred = model.predict(X_test[45].reshape(-1, 784))
print(f"Model's Prediction : {pred}")
print("*"*30)

plt.imshow(X_test[45].reshape(28, 28))
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0967741935483871, 'fraction_numerical': 0.025985663082437275, 'mean_word_length': 7.301115241635688, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 1, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '327953', 'license': 'MIT', 'n_tokens_mistral': 799, 'n_tokens_neox': 744, 'n_words': 203, 'path': 'neural_network/Logistic_Regression.ipynb', 'repo_name': 'tehliang01/Jupyter', 'size': '2232'}