机器学习笔记,使用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

posted @ 2018-04-23 01:04  致林  阅读(9969)  评论(0编辑  收藏  举报