-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics.py
More file actions
executable file
·93 lines (68 loc) · 1.97 KB
/
metrics.py
File metadata and controls
executable file
·93 lines (68 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 16 12:01:04 2018
@author: User
"""
#相关指标计算
#%% 绘制ROC曲线
from sklearn.metrics import roc_curve
fpr, tpr, thresholds = roc_curve(y_true, pred, pos_label=2)
#%% 计算precision,recall和f1-score
from sklearn.metrics import precision_score, recall_score, f1_score
#数据是list类型
y_true = [0, 1, 1, 0, 1, 0]
y_pred = [1, 1, 1, 0, 0, 1]
p = precision_score(y_true, y_pred, average='binary')
r = recall_score(y_true, y_pred, average='binary')
f1score = f1_score(y_true, y_pred, average='binary')
#数据是ndarray类型
import numpy as np
y_true = np.array([[0, 1, 1],
[0, 1, 0]])
y_pred = np.array([[1, 1, 1],
[0, 0, 1]])
y_true = np.reshape(y_true, [-1])
y_pred = np.reshape(y_pred, [-1])
p = precision_score(y_true, y_pred, average='binary')
r = recall_score(y_true, y_pred, average='binary')
f1score = f1_score(y_true, y_pred, average='binary')
#%% 计算均方差
from sklearn.metrics import mean_squared_error
from math import sqrt
err = sqrt(mean_squared_error(y_true, y_pred))
#%% metircs包括的函数
from sklearn import metrics
dir(metrics)
'''
'accuracy_score',
'auc',
'average_precision_score',
'cluster',
'coverage_error',
'euclidean_distances',
'explained_variance_score',
'f1_score',
'jaccard_similarity_score',
'label_ranking_average_precision_score',
'label_ranking_loss',
'make_scorer',
'matthews_corrcoef',
'mean_absolute_error',
'mean_squared_error',
'mean_squared_log_error',
'median_absolute_error',
'mutual_info_score',
'normalized_mutual_info_score',
'pairwise',
'pairwise_distances',
'pairwise_distances_argmin',
'pairwise_distances_argmin_min',
'precision_recall_curve',
'precision_recall_fscore_support',
'precision_score',
'ranking',
'recall_score',
'regression',
'roc_auc_score',
'roc_curve'
'''