अंकों को सीखना
आप digits dataset पर एक मॉडल बनाएँगे, जो scikit-learn के साथ प्री-लोड आता है. digits dataset में 0 से 9 तक के 8x8 पिक्सेल के हस्तलिखित अंक हैं:
डेटासेट पहले से X_train, y_train, X_test, और y_test में बाँटा गया है, जिसमें 30% डेटा testing के लिए है. लेबल पहले से one-hot encoded vectors हैं, इसलिए आपको Keras की to_categorical() फंक्शन उपयोग करने की ज़रूरत नहीं है.
आइए इस नए model को बनाते हैं!
यह अभ्यास पाठ्यक्रम का हिस्सा है
Keras के साथ डीप लर्निंग परिचय
अभ्यास निर्देश
- 16 न्यूरॉनों वाली एक
Denseलेयर जोड़ें,reluactivation के साथ, और ऐसाinput_shapeदें जो 8x8 अंक इमेज के कुल पिक्सेल लेता हो. - 10 आउटपुट और
softmaxactivation वाली एकDenseलेयर जोड़ें. - अपने मॉडल को
adam,categorical_crossentropy, औरaccuracymetrics के साथ compile करें. X_trainपर prediction करके सुनिश्चित करें कि आपका मॉडल काम कर रहा है.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Instantiate a Sequential model
model = Sequential()
# Input and hidden layer with input_shape, 16 neurons, and relu
model.add(Dense(____, input_shape = (____,), activation = ____))
# Output layer with 10 neurons (one per digit) and softmax
model.____(____)
# Compile your model
model.____(optimizer = ____, loss = ____, metrics = [____])
# Test if your model is well assembled by predicting before training
print(model.predict(____))