A mathematical expression/ model for a algorithm

56 Views Asked by At

I have created a simple algorithm in Python to create an ensemble deep-learning model to improve the accuracy of prediction. It's similar to a grid search method which I used to find the perfect weight between 0.0 to 0.5

following is my algorithm in python

import pandas as pd
df = pd.DataFrame([])

for w1 in range(0, 5):
    for w2 in range(0,5):
        for w3 in range(0,5):
            wts = [w1/10.,w2/10.,w3/10.]
            wted_preds1 = np.tensordot(preds1, wts, axes=((0),(0)))
            wted_ensemble_pred = np.argmax(wted_preds1, axis=1)
            weighted_accuracy = accuracy_score(train_image_labels, wted_ensemble_pred)
            df = df.append(pd.DataFrame({'wt1':wts[0],'wt2':wts[1], 
                                         'wt3':wts[2], 'acc':weighted_accuracy*100}, index=[0]), ignore_index=True)
            

what I exactly do is ...I have 03 nested for loops its range between 0 to 5. w1,w2,w3 represent the weight I will use to the multiplication of my predictions.

  1. After in each iteration I ll divide the weight by 10 so it will be 0.0 to 0.5
  2. tensportdot python function is used to multidimensional array multiplication (it will multiply the predictions with the weight)
  3. then using argmax I will retrieve the maximum prediction value
  4. then using accuracy_Score function I will compare my actual predictions with predictions in step 3
  5. print all the combinations of weights and respective accuracy (altogether 125 iterations)
  6. Finally once the loop is finished I obtained the maximum accuracy and respective three weights as this is ensemble of three deep learning models

I know how to represent this in a flowchart but I don't have that much background in representing this as a mathematical expression or model. Hence I really appreciate your expert guidance and solutions on this on how to represent this in mathematical form