Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

You can calculate the Matthews correlation coefficient (MCC) using the matthews_corrcoef

function from the sklearn.metrics module in Python. Here's how:


from sklearn.metrics import matthews_corrcoef

# Sample data (replace with your actual data)


y_true = [1, 1, 0, 0, 1, 0, 1, 0, 1, 0]
y_pred = [1, 1, 1, 0, 0, 0, 1, 0, 0, 1]

# Calculate MCC
mcc = matthews_corrcoef(y_true, y_pred)

# Print the MCC value


print(f"Matthews correlation coefficient (MCC): {mcc:.4f}")

The matthews_corrcoef function takes two arguments:


● y_true: Ground truth (correct) target values.
● y_pred: Estimated targets as returned by a classifier.
The function returns a float value between -1 and +1, where:
● +1 represents a perfect prediction.
● 0 represents an average random prediction.
● -1 indicates an inverse prediction.

You might also like