0

I have an information criterion with help of Gini. How can I change my code for Mean Squared Error instead of Gini? Python, the random forest task.

def gini(labels):
    #  to count the number of objects for different classes
    classes = {}
    for label in labels:
        if label not in classes:
            classes[label] = 0
        classes[label] += 1
    
    #  to calculate Gini criterion
    impurity = 1
    for label in classes:
        p = classes[label] / len(labels)
        impurity -= p ** 2
    return impurity
Toshik
  • 61
  • 5

0 Answers0