Saya menggunakan teknik smote untuk mengecualikan dataset saya dan sekarang saya memiliki dataset yang seimbang. Masalah yang saya hadapi adalah metrik kinerja; presisi, recall, ukuran f1, akurasi dalam dataset tidak seimbang lebih baik dilakukan daripada dengan dataset seimbang.
Pengukuran mana yang dapat saya gunakan untuk menunjukkan bahwa menyeimbangkan dataset dapat meningkatkan kinerja model?
NB: roc_auc_score lebih baik di datset seimbang daripada roc_auc_score dengan dataset tidak seimbang. Apakah ini dapat dianggap sebagai pengukuran kinerja yang baik? setelah penjelasan saya menerapkan kode dan saya mendapat hasil ini
import pandas as pd
import numpy as np
from sklearn import preprocessing
import matplotlib.pyplot as plt
plt.rc("font", size=14)
from sklearn.svm import LinearSVC
from sklearn.svm import SVC
from sklearn.cross_validation import train_test_split,StratifiedShuffleSplit,cross_val_score
import seaborn as sns
from scipy import interp
from time import *
from sklearn import metrics
X=dataCAD.iloc[:,0:71]
y= dataCAD['Cardio1']
# Split the dataset in two equal parts
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=0)
print(y_test.value_counts())
model=SVC(C=0.001, kernel="rbf",gamma=0.01, probability=True)
t0 = time()
clf = model.fit(X_train,y_train)
y_pred = clf.predict(X_test)
t = time() - t0
print("=" * 52)
print("time cost: {}".format(t))
print()
print("confusion matrix\n", metrics.confusion_matrix( y_test, y_pred))
cf=metrics.confusion_matrix(y_test, y_pred)
accuracy=(cf.item((0,0))/50)+(cf.item((1,1))/14)
print("model accuracy \n",accuracy/2)
print()
print("\t\tprecision_score: {}".format(metrics.precision_score( y_test, y_pred, average='macro')))
print()
print("\t\trecall_score: {}".format(metrics.recall_score(y_test, y_pred, average='macro')))
print()
print("\t\tf1_score: {}".format(metrics.f1_score(y_test, y_pred, average='macro')))
print()
print("\t\troc_auc_score: {}".format(metrics.roc_auc_score( y_test, y_pred, average='macro')))
Hasil:
Name: Cardio1, dtype: int64
====================================================
time cost: 0.012008905410766602
confusion matrix
[[50 0]
[14 0]]
model accuracy
0.5
precision_score: 0.390625
recall_score: 0.5
f1_score: 0.43859649122807015
roc_auc_score: 0.5
Untuk dataset seimbang
X_train1,y_train1 = sm.fit_sample(X_train, y_train.ravel())
df= pd.DataFrame({'Cardio1': y_train1})
df.groupby('Cardio1').Cardio1.count().plot.bar(ylim=0)
plt.show()
print(X_train1.shape)
print(y_train1.shape)
#model=SVC(C=0.001, kernel="rbf",gamma=0.01, probability=True)
model=SVC(C=10, kernel="sigmoid",gamma=0.001, probability=True)
t0 = time()
clf = model.fit(X_train1,y_train1)
y_pred = clf.predict(X_test)
t = time() - t0
print("=" * 52)
print("time cost: {}".format(t))
print()
print("confusion matrix\n", metrics.confusion_matrix(y_test, y_pred))
cf=metrics.confusion_matrix(y_test, y_pred)
accuracy=(cf.item((0,0))/50)+(cf.item((1,1))/14)
print("model accuracy \n",accuracy/2)
print()
#print("\t\taccuracy: {}".format(metrics.accuracy_score( y_test, y_pred)))
print()
print("\t\tprecision_score: {}".format(metrics.precision_score( y_test, y_pred, average='macro')))
print()
print("\t\trecall_score: {}".format(metrics.recall_score(y_test, y_pred, average='macro')))
print()
print("\t\tf1_score: {}".format(metrics.f1_score(y_test, y_pred, average='macro')))
print()
print("\t\troc_auc_score: {}".format(metrics.roc_auc_score( y_test, y_pred, average='macro')))
Hasil:
(246, 71)
(246,)
====================================================
time cost: 0.05353999137878418
confusion matrix
[[ 0 50]
[ 0 14]]
model accuracy
0.5
precision_score: 0.109375
recall_score: 0.5
f1_score: 0.1794871794871795
roc_auc_score: 0.5
Saya tidak menemukan hasil yang efisien. Haruskah saya menerapkan model menggunakan validasi silang?