<jupyter_start><jupyter_text><jupyter_code># 下载并安装tensorflow2.0测试包
try:
    %tensorflow_version 2.x
except Exception:
    pass
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np

# 获取数据集
mnist = tf.keras.datasets.mnist

(x_train,y_train),(x_test,y_test) = mnist.load_data()
# 转化图片
x_train,t_test = x_train/255.0,x_test/255.0
# 构建模型
model = tf.keras.models.Sequential([
     tf.keras.layers.Flatten(input_shape=(28,28)),
     tf.keras.layers.Dense(128,activation='relu'),
     tf.keras.layers.Dropout(0.2),
     tf.keras.layers.Dense(10,activation='softmax')                               
])
# 编译模型
model.compile(optimizer='adam',loss=tf.losses.sparse_categorical_crossentropy,metrics=['accuracy'])
# 训练模型
model.fit(x_train,y_train,epochs=10)
plt.imshow(x_test[0],cmap=plt.cm.binary)
plt.show()
np.argmax(model.predict(x_test)[0])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14705882352941177, 'fraction_numerical': 0.029411764705882353, 'mean_word_length': 4.9, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '633990', 'license': 'Apache-2.0', 'n_tokens_mistral': 396, 'n_tokens_neox': 392, 'n_words': 42, 'path': 'tensorflow_v2_beginner.ipynb', 'repo_name': 'RainliFu/tensorflow-udacity', 'size': '884'}