Exemplo n.º 1
0
def plot_loss(data, title):
    print("plotting loss")

    for item in data:
        plt.plot(k_set, item)

    plt.title("loss over time")
    plt.xlabel("iterations")
    plt.ylabel("loss")
    plt.legends(["test, training"])

    plt.savefig(title)
Exemplo n.º 2
0
def plot2(assets_):
    assets = assets_.pct_change()
    plt.figure(figsize=[12, 6])
    plt.plot(assets)
    plt.legends(assest.columns)
    plt.title("Assets Return")
    plt.ylabel("Return")
    plt.xlabel("Time")
    plt.show()

    plt.figure(figsize=[6, 6])
    sns.heatmap(assets.corr(), annot=True, cbar=False)
    plt.yticks(rotation=0)
    ptl.title("Correlation Heatmap")

    plt.show()
Exemplo n.º 3
0
        delta3[range(num_examples), y] -= 1
        dW2 = (a1.T).dot(delta3)
        db2 = np.sum(delta3, axis=0, keepdims=True)
        delta2 = delta3.dot(W2.T) * (1 - np.power(a1, 2))
        dW1 = np.dot(X.T, delta2)
        db1 = np.sum(delta2, axis=0)
        # Add regularization terms (b1 and b2 don't have regularization terms)
        dW2 += reg_lambda * W2
        dW1 += reg_lambda * W1
        # Gradient descent parameter update
        W1 += -epsilon * dW1
        b1 += -epsilon * db1
        W2 += -epsilon * dW2
        b2 += -epsilon * db2
        # Assign new parameters to the model
        model = {'W1': W1, 'b1': b1, 'W2': W2, 'b2': b2}
    return model

# Build a model with a 3-dimensional hidden layer
num_examples = len(X)  # training set size
nn_input_dim = 2  # input layer dimensionality
nn_output_dim = 2  # output layer dimensionality
model = build_model(3, print_loss=True)
print("Loss after all iteration %f" % ( calculate_loss(model)))

# Plot the decision boundary
plot_decision_boundary(lambda x: predict(model, x))
plt.title("Decision Boundary for hidden layer size 3")
plt.legends()
plt.show()
Exemplo n.º 4
0
    def Train_the_Yolo(self,
                       model_name='yolov4.h5',
                       input_shape=(608, 608),
                       plot_model=False,
                       save_weights=False,
                       score=0.5,
                       iou=0.5,
                       epochs1=51,
                       epochs2=50,
                       batch_size1=32,
                       batch_size2=4,
                       gpu_num=1,
                       validation_split=0.1,
                       process1=True,
                       process2=True):

        print('\n\t\t------------Training Phase Generated---------')

        yolo_file_path = os.path.join(self.working_directory, model_name)
        self.class_path = os.path.join(self.output_directory,
                                       'data_classes.txt')
        self.anchors_path = os.path.join(os.path.dirname(__file__),
                                         'yolo4_anchors.txt')
        self.weight_path = os.path.join(self.working_directory,
                                        'yolov4.weights')
        self.coco_class = os.path.join(os.path.dirname(__file__),
                                       'coco_classes.txt')
        #Checking whether User have Yolo File or Not
        #If no File, then it will be downloaded Automatically and Converted to Keras Model
        if not os.path.exists(yolo_file_path):

            Download_weights(output_directory=self.output_directory)
            yolov4 = Yolo4_weights(score=score,
                                   iou=iou,
                                   anchors_path=self.anchors_path,
                                   classes_path=self.coco_classes_path,
                                   model_path=yolo_file_path,
                                   weights_path=self.weight_path,
                                   gpu_num=gpu_num)
            yolov4.load_yolo()

        print('Model Training to be Start ....')
        history = Train_Yolo(working_directory=self.working_directory,
                             output_directory=self.output_directory,
                             model_name=model_name,
                             val_split=validation_split,
                             epochs1=epochs1,
                             epochs2=epochs2,
                             batch_size1=batch_size1,
                             batch_size2=batch_size2,
                             process1=process1,
                             process2=process2)

        self.history = history

        try:
            plt.plot(self.history.history['loss'], label='Training Loss')
            plt.plot(self.history.history['val_loss'], label='Validation Loss')
            plt.title('Training Loss vs Validation Loss')
            plt.legends()
            plt.show()

        except:
            pass
Exemplo n.º 5
0
                         activation = ACTFUNC,               # Activation function of neurons is Rectified Linear Unit function or ‘relu’.
                         input_dim = X_train.shape[1]))           # Equal to the # of columns of input, Price Rise
    classifier.add(Dense(units = 128, kernel_initializer = 'uniform', activation = ACTFUNC)) # a hidden middle layer
    classifier.add(Dense(units = 128, kernel_initializer = 'uniform', activation = ACTFUNC)) # a hidden middle layer
    classifier.add(Dense(units = len(y_train.T), kernel_initializer = 'uniform', activation = ACTFUNC)) # a hidden middle layer
    classifier.compile(optimizer = 'adam',                  # an extension of gradient descent
                       loss = 'mean_squared_error', 
                       metrics = ['accuracy'])              # what to evaulate during optimization
    classifier.fit(X_train, y_train.values, batch_size = 5, epochs = 200)
    return classifier
classifier = BuildtheNetwork(XX, Y)
y_pred = classifier.predict(XX)

def plotANNaccuracy():
    plt.plot(XX.T['10']);plt.title('INPUT, returns');plt.show()
    #plt.plot(y_pred.T);plt.title('Outcome, ANN output');plt.show()
    plt.plot(Y.T);plt.title('Target');plt.show()
    Output = pd.DataFrame(y_pred.T, index = Y.T.index)
    plt.plot(Output);plt.title('Outcome, ANN output');plt.show()
#plotANNaccuracy()
#classifier.save('my_model.h5')
    
    
plt.plot(range(49),XX.T['10.18'],color = 'k', label = 'Distruption of 10')
plt.plot(range(49),XX.T['5.35'], label = 'Distruption of 5');plt.title('INPUT, returns')
plt.legend();plt.show()
#plt.plot(y_pred.T);plt.title('Outcome, ANN output');plt.show()
plt.plot(range(49),Y.T['10.18'],color = 'k', label = 'Distruption of 10')
plt.plot(range(49),Y.T['5.35'], label = 'Distruption of 5');plt.title('Output, Training Target')
plt.legends();plt.show()