[Python] Iterator name does not count as it's supposed name in a for loop

Discussão em 'Python' iniciado por Stack, Junho 25, 2025.

  1. Stack

    Stack Membro Participativo

    cancer = load_breast_cancer()

    X, y = cancer.data, cancer.target
    X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)

    model = LogisticRegression(random_state=42).fit(X_train, y_train)
    y_preds = model.predict(X_test)
    metrics = [confusion_matrix, precision_score, recall_score, f1_score]

    for metric in metrics:
    print(f"Metric:{metric}\nAccuracy:{model.metric(y_test, y_preds)}\n--------")


    Here in metric I get an error AttributeError: 'LogisticRegression' object has no attribute 'metric' even though I imported everything correctly. Doesn't this have to do that metric operation at every iteration.

    Continue reading...

Compartilhe esta Página