• 1000 и так далее, каждый раз, когда меняют точность. Следует ли мне придерживаться самого первого раза или попробовать несколько раз. Это признак переобучения или чего-то еще?
import numpy as np
import tensorflow as tf
from imgaug.augmenters import Dropout
from sklearn.model_selection import cross_val_score
from keras.wrappers.scikit_learn import KerasClassifier
data = np.load('subclass_features.npy', allow_pickle=True)
from sklearn.model_selection import train_test_split
training_data = np.asarray([i[0] for i in data]) # select upto second last
train_labels = data[:, -1] # gives the last column vector
print("Shape of training data", training_data.shape)
print("Labels of training data", train_labels.shape)
data = training_data.astype('float32')
data = data / 255
from tensorflow.keras import utils as np_utils
one_hot_train_labels = np_utils.to_categorical(train_labels)
# train_data1, test_data1, train_labels1, test_labels1 = train_test_split(train_data, one_hot_train_labels,random_state=0, test_size=0.3)
def built_classifier():
classifier = tf.keras.models.Sequential()
classifier.add(tf.keras.layers.Dense(64, input_shape=(128,), activation='relu'))
classifier.add(tf.keras.layers.Dense(4, activation='softmax'))
classifier.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
classifier.save('SubClassPredictions.h5')
return classifier
classifier = KerasClassifier(build_fn=built_classifier, epochs=50, batch_size=32, shuffle=True)
accuracies = cross_val_score(classifier, data, one_hot_train_labels, cv=10)
print("Data Accuracy", accuracies)
print("Mean of accuracy is", accuracies.mean())