old_contents: import numpy as np
  from keras.models import Sequential
  from keras.layers.core import Dense, Dropout, Activation
  from keras.optimizers import SGD
  from keras.utils import np_utils
  
  
  def main():
      #data_dir = '../data_mini'
      data_dir = '../data'
      out_dir = '..'
      input_dim = 784
      nb_hidden_units = [128, 128, 128, 128]
      batch_size = 128
      nb_classes = 10
      nb_epoch = 100  # 1つのテストデータを何回学習するか
      dropout_ratio = 0.1
      validation_ratio = 0.2
      weight_decay = 1e-4
      momentum = 0.9
      learning_rate = 0.01
  
      # 訓練集合、テスト集合の準備
      X_train = np.loadtxt(data_dir + '/train.csv', delimiter=',', skiprows=1, usecols=range(1, input_dim + 1))
      y_train = np.loadtxt(data_dir + '/train.csv', delimiter=',', skiprows=1, usecols=[0])
      Y_train = np_utils.to_categorical(y_train, nb_classes)
  
      X_test = np.loadtxt(data_dir + '/test.csv', delimiter=',', skiprows=1, usecols=range(input_dim))
  
      # モデル構築・初期化
      model = Sequential()
  
      model.add(Dense(nb_hidden_units[0], input_shape=(input_dim,), init='uniform'))
      model.add(Activation('relu'))
      model.add(Dropout(dropout_ratio))
  
      for l in range(1, len(nb_hidden_units)):
          model.add(Dense(nb_hidden_units[l], init='uniform'))
          model.add(Activation('relu'))
          model.add(Dropout(dropout_ratio))
  
      model.add(Dense(nb_classes, init='uniform'))
      model.add(Activation('softmax'))
  
      sgd = SGD(lr=learning_rate, decay=weight_decay, momentum=momentum, nesterov=True)
      model.compile(loss='mean_squared_error', optimizer=sgd)
  
      # 学習・検証
      model.fit(
          X_train, Y_train, nb_epoch=nb_epoch,
          batch_size=batch_size, validation_split=validation_ratio,
          show_accuracy=True)
  
      # テスト集合に対する予測結果の出力
      classes = model.predict_classes(X_test, batch_size=batch_size)
      print(classes)
      np.savetxt(
          out_dir + '/ans.csv', np.dstack((range(1, len(classes) + 1), classes))[0],
          delimiter=',', header='ImageId,Label', comments='', fmt='%i')
  
  
  if __name__ == '__main__':
      main()
  
new_contents: import numpy as np
  from keras.models import Sequential
  from keras.layers.core import Dense, Dropout, Activation
  from keras.optimizers import SGD
  from keras.utils import np_utils
  
  
  def main():
      #data_dir = '../data_mini'
      data_dir = '../data'
      out_dir = '..'
      input_dim = 784
      scale = 255.0  # CSVの各要素は[0,255]
      nb_hidden_units = [128, 128, 128, 128]
      batch_size = 128
      nb_classes = 10
      nb_epoch = 20  # 1つのテストデータを何回学習するか
      dropout_ratio = 0.1
      validation_ratio = 0.2
      weight_decay = 1e-4
      momentum = 0.9
      learning_rate = 0.1
  
      # 訓練集合、テスト集合の準備
      X_train = np.loadtxt(data_dir + '/train.csv', delimiter=',', skiprows=1, usecols=range(1, input_dim + 1))
      y_train = np.loadtxt(data_dir + '/train.csv', delimiter=',', skiprows=1, usecols=[0])
      Y_train = np_utils.to_categorical(y_train, nb_classes)
      X_test = np.loadtxt(data_dir + '/test.csv', delimiter=',', skiprows=1, usecols=range(input_dim))
  
      # 前処理
      mean = np.average(X_train, axis=0)
      X_train -= mean
      X_test -= mean
  
      # モデル構築・初期化
      model = Sequential()
  
      model.add(Dense(nb_hidden_units[0], input_shape=(input_dim,), init='uniform'))
      model.add(Activation('relu'))
      model.add(Dropout(dropout_ratio))
  
      for l in range(1, len(nb_hidden_units)):
          model.add(Dense(nb_hidden_units[l], init='uniform'))
          model.add(Activation('relu'))
          model.add(Dropout(dropout_ratio))
  
      model.add(Dense(nb_classes, init='uniform'))
      model.add(Activation('softmax'))
  
      sgd = SGD(lr=learning_rate, decay=weight_decay, momentum=momentum, nesterov=True)
      model.compile(loss='mean_squared_error', optimizer=sgd)
  
      # 学習・検証
      model.fit(
          X_train, Y_train, nb_epoch=nb_epoch,
          batch_size=batch_size, validation_split=validation_ratio,
          show_accuracy=True)
  
      # テスト集合に対する予測結果の出力
      classes = model.predict_classes(X_test, batch_size=batch_size)
      print(classes)
      np.savetxt(
          out_dir + '/ans.csv', np.dstack((range(1, len(classes) + 1), classes))[0],
          delimiter=',', header='ImageId,Label', comments='', fmt='%i')
  
  
  if __name__ == '__main__':
      main()
  
subject: subtract mean over figures