1. 賽題資料
import pandas as pd
import numpy as np
train = pd.read_csv(
'train.csv'
)testa = pd.read_csv(
'testa.csv'
)
('train data shape:'
,train.shape)
('testa data shape:'
,testa.shape)
train data shape: (800000, 47)
testa data shape: (200000, 46)
train.head(
)
idloanamnt
term
interestrate
installment
grade
subgrade
employmenttitle
employmentlength
homeownership
...n5
n6n7
n8n9
n10n11
n12n13
n140
035000.0
519.52
917.97ee2
320.0
2 years
2...
9.08.0
4.012.0
2.07.0
0.00.0
0.02.011
18000.0
518.49
461.90dd2
219843.0
5 years
0...
nannan
nannan
nan13.0
nannan
nannan22
12000.0
516.99
298.17dd3
31698.0
8 years
0...
0.021.0
4.05.0
3.011.0
0.00.0
0.04.033
11000.0
37.26
340.96aa4
46854.0
10+ years
1...
16.0
4.07.0
21.0
6.09.0
0.00.0
0.01.044
3000.0
312.99
101.07cc2
54.0
nan1
...4.0
9.010.0
15.0
7.012.0
0.00.0
0.04.0
5 rows × 47 columns
## 混淆矩陣
import numpy as np
from sklearn.metrics import confusion_matrix
y_pred =[0
,1,0
,1]y_true =[0
,1,1
,0]print
('混淆矩陣:\n'
,confusion_matrix(y_true, y_pred)
)
混淆矩陣:
[[1 1]
[1 1]]
## accuracy
from sklearn.metrics import accuracy_score
y_pred =[0
,1,0
,1]y_true =[0
,1,1
,0]print
('acc:'
,accuracy_score(y_true, y_pred)
)
acc: 0.5
## precision,recall,f1-score
from sklearn import metrics
y_pred =[0
,1,0
,1]y_true =[0
,1,1
,0]print
('precision'
,metrics.precision_score(y_true, y_pred)
('recall'
,metrics.recall_score(y_true, y_pred)
('f1-score:'
,metrics.f1_score(y_true, y_pred)
)
precision 0.5
recall 0.5
f1-score: 0.5
## p-r曲線
import matplotlib.pyplot as plt
from sklearn.metrics import precision_recall_curve
y_pred =[0
,1,1
,0,1
,1,0
,1,1
,1]y_true =[0
,1,1
,0,1
,0,1
,1,0
,1]precision, recall, thresholds = precision_recall_curve(y_true, y_pred)
plt.plot(precision, recall)
[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-gsyirxsw-1600180106036)(output_8_1.png)]
## roc曲線
from sklearn.metrics import roc_curve
y_pred =[0
,1,1
,0,1
,1,0
,1,1
,1]y_true =[0
,1,1
,0,1
,0,1
,1,0
,1]fpr,tpr,thresholds=roc_curve(y_true, y_pred)
plt.title(
'roc'
)plt.plot(fpr, tpr,
'b')
plt.plot([0
,1],
[0,1
],'r--'
)plt.ylabel(
'tpr'
)plt.xlabel(
'fpr'
)
text(0.5, 0, 'fpr')
[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-ubtj4vih-1600180106041)(output_9_1.png)]
## auc
import numpy as np
from sklearn.metrics import roc_auc_score
y_true = np.array([0
,0,1
,1])
y_scores = np.array(
[0.1
,0.4
,0.35
,0.8])
('auc socre:'
,roc_auc_score(y_true, y_scores)
)
auc socre: 0.75
## ks值 在實際操作時往往使用roc曲線配合求出ks值
from sklearn.metrics import roc_curve
y_pred =[0
,1,1
,0,1
,1,0
,1,1
,1]y_true =[0
,1,1
,0,1
,0,1
,1,1
,1]fpr,tpr,thresholds=roc_curve(y_true, y_pred)
ks=abs
(fpr-tpr)
.max()
('ks值:'
,ks)
ks值: 0.5238095238095237
def
score
(prob,p0=
600,pdo=
20,badrate=
none
,goodrate=
none):
p0 = p0
pdo = pdo
theta0 = badrate/goodrate
b = pdo/np.log(2)
a = p0 + b*np.log(
2*theta0)
score = a-b*np.log(prob/(1
-prob)
)return score
Task1 賽題理解
賽題是cv入門級賽題,通過街景字元識別來熟悉cv建模思路和競賽流程。目標為識別街景中的字元。資料集樣本展示如下 評價指標如下 主要考慮兩種思路 傳統cv思路 先將影象二值化處理,然後做傾斜校正,根據投影做字元切割,根據0 9的字元的特徵點與標準字元匹配來進行識別 深度學習思路 本題本質上是分類問題,...
Task1 賽題理解
鏈結 賽題資料由以下幾個部分構成 訓練集20w條樣本,測試集a包括5w條樣本,測試集b包括5w條樣本。為了預防選手人工標註測試集的情況,我們將比賽資料的文字按照字元級別進行了匿名處理。在資料集中標籤的對應的關係如下 評價標準為類別f1 score的均值,選手提交結果與實際測試集的類別進行對比,結果越...
task1 賽題理解
task1 賽題理解 本次組隊學習的任務是典型的貸款違約問題,即通過所給的關與貸款者的各項字段特徵去判斷該客戶是否是潛在的違約客戶,這類題在各類風控問題中常常出現,因為不同銀行或機構所掌握的客戶資訊不同,每個特徵也不同,所以如何利用字段特徵,成為了是否能拿高分的關鍵因素 先來看一下題目簡介 賽題以 ...