機器學習筆記,使用metrics.classification_report顯示精確率,召回率,f1指數


sklearn中的classification_report函數用於顯示主要分類指標的文本報告.在報告中顯示每個類的精確度,召回率,F1值等信息。 
主要參數: 
y_true:1維數組,或標簽指示器數組/稀疏矩陣,目標值。 
y_pred:1維數組,或標簽指示器數組/稀疏矩陣,分類器返回的估計值。 
labels:array,shape = [n_labels],報表中包含的標簽索引的可選列表。 
target_names:字符串列表,與標簽匹配的可選顯示名稱(相同順序)。 
sample_weight:類似於shape = [n_samples]的數組,可選項,樣本權重。 
digits:int,輸出浮點值的位數.

    Parameters
    ----------
    y_true : 1d array-like, or label indicator array / sparse matrix
        Ground truth (correct) target values.

    y_pred : 1d array-like, or label indicator array / sparse matrix
        Estimated targets as returned by a classifier.

    labels : array, shape = [n_labels]
        Optional list of label indices to include in the report.

    target_names : list of strings
        Optional display names matching the labels (same order).

    sample_weight : array-like of shape = [n_samples], optional
        Sample weights.

    digits : int
        Number of digits for formatting output floating point values

    Returns
    -------
    report : string
        Text summary of the precision, recall, F1 score for each class.

        The reported averages are a prevalence-weighted macro-average across
        classes (equivalent to :func:`precision_recall_fscore_support` with
        ``average='weighted'``).

        Note that in binary classification, recall of the positive class
        is also known as "sensitivity"; recall of the negative class is
        "specificity".

    Examples
    --------
    >>> from sklearn.metrics import classification_report
    >>> y_true = [0, 1, 2, 2, 2]
    >>> y_pred = [0, 0, 2, 2, 1]
    >>> target_names = ['class 0', 'class 1', 'class 2']
    >>> print(classification_report(y_true, y_pred, target_names=target_names))
                 precision    recall  f1-score   support
    <BLANKLINE>
        class 0       0.50      1.00      0.67         1
        class 1       0.00      0.00      0.00         1
        class 2       1.00      0.67      0.80         3
    <BLANKLINE>
    avg / total       0.70      0.60      0.61         5
    <BLANKLINE>

 

參考:

https://www.programcreek.com/python/example/81623/sklearn.metrics.classification_report

https://blog.csdn.net/akadiao/article/details/78788864


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM