# !/usr/bin/env python3.7
# site:D:\users\lenovo\PycharmProjects\untitled
# Time : 2019/4/11 8:51 
# Author : 御承扬
# e-mail:2923616405@qq.com
# site: 
# File : mnist_code.py 
# @oftware: PyCharm


from sklearn import datasets
import numpy as np
from sklearn.neural_network import MLPClassifier

mnist = datasets.fetch_mldata('MNIST Original',data_home='./')
x, y = mnist['data'],mnist['target']
x_train, x_test, y_train, y_test = x[:60000], x[60000:], y[:60000], y[60000:]

shuffile_index = np.random.permutation(60000)
X_train, Y_train = x_train[shuffile_index], y_train[shuffile_index]

# clf=MLPClassifier(solver='lbfgs',alpha=1e-5,hidden_layer_sizes=(5,2),random_state=1)
# clf.fit(x_train, y_train)
# print(clf.predict_proba(x_test))
# print('=======================================')
# print(y_test)



# import time
# import matplotlib.pyplot as plt
# import numpy as np
# from sklearn import datasets
#
# from sklearn.linear_model import LogisticRegression
# from sklearn.model_selection import train_test_split
# from sklearn.preprocessing import StandardScaler
# from sklearn.utils import check_random_state
#
# print(__doc__)
#
# # Author: Arthur Mensch <arthur.mensch@m4x.org>
# # License: BSD 3 clause
#
# # Turn down for faster convergence
# t0 = time.time()
# train_samples = 5000
#
# # Load data from https://www.openml.org/d/554
# mnist = datasets.fetch_mldata('MNIST Original',data_home='./')
# X, y = mnist['data'],mnist['target']
#
# random_state = check_random_state(0)
# permutation = random_state.permutation(X.shape[0])
# X = X[permutation]
# y = y[permutation]
# X = X.reshape((X.shape[0], -1))
#
# X_train, X_test, y_train, y_test = train_test_split(
#     X, y, train_size=train_samples, test_size=10000)
#
# scaler = StandardScaler()
# X_train = scaler.fit_transform(X_train)
# X_test = scaler.transform(X_test)
#
# # Turn up tolerance for faster convergence
# clf = LogisticRegression(C=50. / train_samples,
#                          multi_class='multinomial',
#                          penalty='l1', solver='saga', tol=0.1)
# clf.fit(X_train, y_train)
# sparsity = np.mean(clf.coef_ == 0) * 100
# score = clf.score(X_test, y_test)
# # print('Best C % .4f' % clf.C_)
# print("Sparsity with L1 penalty: %.2f%%" % sparsity)
# print("Test score with L1 penalty: %.4f" % score)
#
# coef = clf.coef_.copy()
# plt.figure(figsize=(10, 5))
# scale = np.abs(coef).max()
# for i in range(10):
#     l1_plot = plt.subplot(2, 5, i + 1)
#     l1_plot.imshow(coef[i].reshape(28, 28), interpolation='nearest',
#                    cmap=plt.cm.RdBu, vmin=-scale, vmax=scale)
#     l1_plot.set_xticks(())
#     l1_plot.set_yticks(())
#     l1_plot.set_xlabel('Class %i' % i)
# plt.suptitle('Classification vector for...')
#
# run_time = time.time() - t0
# print('Example run in %.3f s' % run_time)
# plt.show()