手写字符识别神经网络项目总结

1.数据集

手写字符数据集 DIGITS,该数据集的全称为  Pen-Based Recognition of Handwritten Digits Data Set,来源于 UCI 开放数据集网站。

2.加载数据集

import numpy as np
from sklearn import datasets

digits = datasets.load_digits()

3.分割数据集

from sklearn.model_selection import train_test_split
X, y = digits.data, digits.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=30)

4. 搭建人工神经网络

from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score

def mpl():
    model = MLPClassifier(hidden_layer_sizes=(100, 50), activation='relu', solver='sgd', learning_rate_init=0.02, max_iter=100, random_state=1)
    model.fit(X_train, y_train)
    y_pred = model.predict(X_test)
    score = accuracy_score(y_test, y_pred)

    return model, score

5.绘制损失变化曲线

model = mpl()[0]
plt.plot(model.loss_curve_)

你可能感兴趣的:(神经网络,人工智能,深度学习)