예제 #1
0
def pure_temp_prediction():
    X = diff_length_csv('tiwencheck.csv')
    X = np.array(X)
    y = fun2('number_category.csv')
    X_train, X_test, y_train, y_test = cross_validation.train_test_split(
        X, y, test_size=0.2)
    y_train = category_to_target(y_train)
    y_test = category_to_target(y_test)

    x_train = reshape_dataset(X_train)
    x_test = reshape_dataset(X_test)
    model = Sequential()
    model.add(LSTM(16, input_shape=(12, 1)))
    model.add(Dropout(0.25))
    model.add(Dense(nb_classes, bias=False))
    model.add(Activation('softmax'))
    model.compile(loss='categorical_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])
    model.summary()

    print('Train...')
    model.fit(x_train,
              y_train,
              batch_size=batch_size,
              nb_epoch=5,
              validation_split=0.05)
    score, acc = model.evaluate(x_test, y_test, batch_size=batch_size)
    print(model.predict_proba(reshape_dataset(X)))
    print('Test score:', score)
    print('Test accuracy:', acc)
예제 #2
0
def length_temp_prediction():
    X = diff_length_csv('5_day_50_check.csv')
    # X=fun2('5_day_50_check.csv')
    # X = pad_sequences(X, maxlen=maxlen, padding='post', truncating='post', dtype='float')
    X = np.array(X, dtype=float)

    y = fun2('number_category.csv')
    X_train, X_test, y_train, y_test = cross_validation.train_test_split(
        X, y, test_size=0.2)
    y_train = category_to_target(y_train)
    y_test = category_to_target(y_test)

    x_train = reshape_dataset(X_train)
    x_test = reshape_dataset(X_test)

    model = Sequential()
    # model.add(Masking(mask_value=0, input_shape=(maxlen, 1)))
    model.add(LSTM(3, input_shape=(maxlen, 1), return_sequences=True))
    model.add(Dropout(0.25))
    model.add(Reshape((maxlen * 3, )))
    model.add(Dense(nb_classes, b_regularizer=l1(0.01)))
    model.add(Dropout(0.25))
    model.add(Activation('softmax'))
    model.compile(loss='categorical_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])
    model.summary()

    print('Train...')
    model.fit(x_train,
              y_train,
              batch_size=batch_size,
              nb_epoch=30,
              validation_split=0.05)
    score, acc = model.evaluate(x_test, y_test, batch_size=batch_size)
    print(model.predict_proba(reshape_dataset(X)))
    print('Test score:', score)
    print('Test accuracy:', acc)
예제 #3
0
    # for i in range(0,maxlen-1):
    #     y_train=np.concatenate((y_train_temp,y_train),axis=1)
    #     y_test=np.concatenate((y_test_temp,y_test),axis=1)
    # print(y_train.shape)

    # x_train represents list temperature
    # x2_train represents test parameter
    x_train = X_train[:, in_file_length:]
    x2_train = X_train[:, 0:len(X2[0])]

    x_test = X_test[:, in_file_length:]
    x2_test = X_test[:, 0:len(X2[0])]

    print('X_train shape:', x_train.shape)
    print('X_test shape:', x_test.shape)
    x_train = reshape_dataset(x_train)
    x_test = reshape_dataset(x_test)
    print('X_train shape:', x_train.shape)
    print('X_test shape:', x_test.shape)

    model1 = Sequential()
    # model1.add(Masking(mask_value=0, input_shape=(maxlen, 1)))
    model1.add(
        LSTM(output_dim=5, input_shape=(maxlen, 1), return_sequences=True))
    model1.add(Dropout(0.25))
    model1.add(Reshape((maxlen * 5, )))

    model2 = Sequential()
    model2.add(Dense(64, input_dim=in_file_length))
    model2.add(Dropout(0.25))
    model2.add(Activation('relu'))