dimanche 10 novembre 2019

I have to develp a model which takes series of random value and gives predicted value (in integer)

I want to train my model on a list of number series. I don't expect it to give high accuracy but at least 25%. I have developed a small model using Sequential() method but at the end it is giving me output in 0.0xy.. This is really worst. I have even tried to build a model using Neural Network on Azure ML workspace but no success.

I have used the code from Github! and its source from here!

I have a file which contains 200,000 random numbers in txt format. I have converted it into csv with 150 values where 150th is the predictable value. Although initially I have taken only 2000 for easy processing with 50 size chunks.

I have searched for this topic and found lots of questions about it but couldn't found a perfect solution.

Here is my build model code

def build_model():
    model = Sequential()
    layers = [1, 50, 100, 1]

    model.add(LSTM(
        layers[1],
        input_shape=(None, layers[0]),
        return_sequences=True))
    model.add(Dropout(0.2))

    model.add(LSTM(
        layers[2],
        return_sequences=False))
    model.add(Dropout(0.2))

    model.add(Dense(
        layers[3]))
    model.add(Activation("linear"))

    start = time.time()
    model.compile(loss="mse", optimizer="rmsprop")
    print("Compilation Time : ", time.time() - start)
    return model

and its running code


def run_network(model=None, data=None):
    global_start_time = time.time()
    epochs = 1
    ratio = 1.0
    sequence_length = 50
    path_to_dataset = open('InputNumber6_demo.txt','r+',encoding = "utf-8-sig")

    if data is None:
        print("Loading data...")
        X_train, y_train, X_test, y_test = dpc.data_power_consumption(
            path_to_dataset, sequence_length, ratio)
    else:
        X_train, y_train, X_test, y_test = data

    print('\nData Loaded. Compiling...\n')

    if model is None:
        model = bm.build_model()

    try:
        model.fit(
            X_train, y_train,
            batch_size=512, nb_epoch=epochs, validation_split=0.05)
        predicted = model.predict(X_test)
        predicted = np.reshape(predicted, (predicted.size,))

    except KeyboardInterrupt:
        print('Training duration (s) : ', time.time() - global_start_time)
        return model, y_test, 0

    try:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.plot(y_test[:100])
        plt.plot(predicted[:100])
        plt.show()
    except Exception as e:
        print(str(e))
    print('Training duration (s) : ', time.time() - global_start_time)
    print("y_test :" ,y_test)
    print("predicted : ", predicted)
    return model, y_test, predicted

I am getting output in this fractions:

 [7.896141  7.8818192 7.8702197 7.8729057 7.887852  7.8909307 7.880986
 7.8800116 7.8971305 7.8821206 7.872368  7.8670635 7.859713  7.866045
 7.895461  7.884264  7.89429   7.891604  7.9120145 7.9183216 7.9248204
 7.9104924 7.9158993 7.897169  7.916412  7.9040785 7.920195  7.9250274
 7.933447  7.93625   7.8920164 7.9262824 7.9311395 7.936692  7.943627
 7.9117746 7.921586  7.9338064 7.9352465 7.913917  7.9132504 7.9155235
 7.892686  7.8813086 7.904029  7.902289  7.886468  7.88697   7.920277
 7.9392414 7.935853  7.9325123 7.9430776 7.9166965 7.8978596]

Please tell me the issue in this case or is there any algorithm to create the model




Aucun commentaire:

Enregistrer un commentaire