<jupyter_start><jupyter_text>执行阶段<jupyter_code># 加载数据
train_df = pd.read_csv("./datasets/train.csv")
test_df = pd.read_csv("./datasets/test.csv")
combine = [train_df, test_df]
# 定义执行步数和 小批量更新的实例数
n_epochs = 50
batch_size = 50
train_df.head()
X_train = train_df.drop(["label"], axis=1)

y_train = train_df["label"]

from sklearn.preprocessing import StandardScaler
X_train_scaled = StandardScaler().fit_transform(X_train)
X_test_scaled = StandardScaler().fit_transform(test_df)
X_train, X_test , y_train, y_test = train_test_split(X_train_scaled, y_train, test_size=0.1)
X_train.shape, X_test.shape, y_train.shape
    m, n = X_train.shape
# 训练模型
with tf.Session() as sess:
    init.run()
    for epoch in range(n_epochs):
        for iteration in range(m // batch_size):
            X_batch = X_train[iteration: iteration + batch_size]
            y_batch = y_train.iloc[iteration: iteration + batch_size].values
            sess.run(training_op, feed_dict={X:X_batch, y:y_batch})
        acc_train = accuracy.eval(feed_dict={X:X_test, y:y_test})
        print(epoch, "train accurancy:", acc_train)
    save_path = saver.save(sess, "./model/final.ckpt")
# 重载模型， 进行预测
with tf.Session() as sess:
    saver.restore(sess, "./model/final.ckpt")
    Z = logits.eval(feed_dict={X:X_test_scaled})
    y_pred = np.argmax(Z, axis=1)

# 保存结果到文件
# ImageId = np.arange(1, 28001)
# result = pd.DataFrame({
#     "ImageId": ImageId,
#     "Label": y_pred
# })
# result.to_csv("result.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1424802110817942, 'fraction_numerical': 0.009234828496042216, 'mean_word_length': 4.398576512455516, 'pattern_counts': {'":': 2, '<': 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': '482480', 'license': 'Apache-2.0', 'n_tokens_mistral': 630, 'n_tokens_neox': 633, 'n_words': 103, 'path': 'digit_recognizer/02.ipynb', 'repo_name': 'yunshuipiao/sw_kaggle', 'size': '1516'}