antitheft159 commited on
Commit
629e3dd
·
verified ·
1 Parent(s): dee6601

Upload quantumjump_195.py

Browse files
Files changed (1) hide show
  1. quantumjump_195.py +115 -0
quantumjump_195.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """quantumjump.195
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1ajVqXJvko89LMeo0a9e_uB75te2fLwMY
8
+ """
9
+
10
+ # Commented out IPython magic to ensure Python compatibility.
11
+ import tensorflow as tf
12
+ from tensorflow import keras
13
+ import matplotlib.pyplot as plt
14
+ # %matplotlib inline
15
+ import numpy as np
16
+
17
+ (X_train, y_train), (X_test, y_test) = keras.datasets.mnist.load_data()
18
+
19
+ len(X_train)
20
+
21
+ len(X_test)
22
+
23
+ X_train[0].shape
24
+
25
+ X_train[0]
26
+
27
+ plt.matshow(X_train[2])
28
+
29
+ y_train[2]
30
+
31
+ y_train[:5]
32
+
33
+ X_train.shape
34
+
35
+ X_train = X_train / 255
36
+ X_test = X_test / 255
37
+
38
+ X_train[0]
39
+
40
+ X_train_flattened = X_train.reshape(len(X_train),28*28)
41
+ X_test_flattened = X_test.reshape(len(X_test),28*28)
42
+
43
+ X_train_flattened.shape
44
+
45
+ X_train_flattened[0]
46
+
47
+ model = keras.Sequential([
48
+ keras.layers.Dense(10, input_shape=(784,),activation='sigmoid')
49
+ ])
50
+
51
+ model.compile(
52
+ optimizer='adam',
53
+ loss='sparse_categorical_crossentropy',
54
+ metrics=['accuracy']
55
+ )
56
+ model.fit(X_train_flattened, y_train, epochs=5)
57
+
58
+ model.evaluate(X_test_flattened, y_test)
59
+
60
+ plt.matshow(X_test[0])
61
+
62
+ y_predicted = model.predict(X_test_flattened)
63
+ y_predicted[0]
64
+
65
+ np.argmax(y_predicted[1])
66
+
67
+ y_predicted_labels = [np.argmax(i) for i in y_predicted]
68
+ y_predicted_labels[:5]
69
+
70
+ y_test[:5]
71
+
72
+ cm = tf.math.confusion_matrix(labels=y_test,predictions=y_predicted_labels)
73
+ cm
74
+
75
+ import seaborn as sn
76
+ plt.figure(figsize = (10,7))
77
+ sn.heatmap(cm, annot=True, fmt='d')
78
+ plt.xlabel('Predicted')
79
+ plt.ylabel('Truth')
80
+
81
+ model = keras.Sequential([
82
+ keras.layers.Dense(100, input_shape=(784,), activation='relu'),
83
+ keras.layers.Dense(10, activation='sigmoid')
84
+ ])
85
+
86
+ model.compile(
87
+ optimizer='adam',
88
+ loss='sparse_categorical_crossentropy',
89
+ metrics=['accuracy']
90
+ )
91
+ model.fit(X_train_flattened, y_train, epochs=5)
92
+
93
+ model.evaluate(X_test_flattened,y_test)
94
+
95
+ y_predicted = model.predict(X_test_flattened)
96
+ y_predicted_labels = [np.argmax(i) for i in y_predicted]
97
+ cm = tf.math.confusion_matrix(labels=y_test, predictions=y_predicted_labels)
98
+
99
+ plt.figure(figsize = (10,7))
100
+ sn.heatmap(cm, annot=True, fmt='d')
101
+ plt.xlabel('Predicted')
102
+ plt.ylabel('Truth')
103
+
104
+ model = keras.Sequential([
105
+ keras.layers.Dense(100, input_shape=(784,),activation='relu'),
106
+ keras.layers.Dense(10, activation='sigmoid')
107
+ ])
108
+
109
+ model.compile(
110
+ optimizer = 'adam',
111
+ loss='sparse_categorical_crossentropy',
112
+ metrics=['accuracy']
113
+ )
114
+
115
+ model.fit(X_train_flattened, y_train, epochs=5)