dbscan用于信用卡欺诈检测系统

时间:2018-02-07 06:31:46

标签: python machine-learning dbscan

为什么在使用DBSCAN的以下代码的帮助下不会发生群集。所有记录都被视为异常值(聚集到标签-1)

Dataset Attributes:(UCI rep dataset)
ID,LIMIT_BAL,SEX,EDUCATION,MARRIAGE,AGE,PAY_0,PAY_2,PAY_3,PAY_4,PAY_5,PAY_6,BILL_AMT1,BILL_AMT2,BILL_AMT3,BILL_AMT4,BILL_AMT5,BILL_AMT6,PAY_AMT1,PAY_AMT2,PAY_AMT3,PAY_AMT4,PAY_AMT5,PAY_AMT6,dpnm

这是代码

import pandas as pd
from sklearn.cluster import DBSCAN
from sklearn.cross_validation import train_test_split
from sklearn.metrics import confusion_matrix
data1=pd.read_csv("dataset.csv",skiprows=1)
data=data1[data1.columns[0:24]]
X = data.iloc[:,1:]
y = data1.iloc[:,24:]
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
db=DBSCAN(eps=0.5,min_samples=10, algorithm='auto',random_state=0)
db.fit(X_train,y_train)
y_pred=db.fit_predict(X_test)
print y_pred
confusion_matrix = confusion_matrix(y_test, y_pred)
print(confusion_matrix)

我得到的输出是:

[-1 -1 -1 ..., -1 -1 -1]

[[   0    0    0]

 [5868    0    0]

 [1632    0    0]]

应该修改代码以便成功执行群集... 我是ML的初学者

1 个答案:

答案 0 :(得分:0)

群集不是监督学习。

fit的重复调用,火车测试分割以及您的评估对于无监督学习毫无用处。因为它是无人监督的,所以它不会从训练数据中学习。如果您有标记数据,总是更喜欢监督方法。

群集是,您需要仔细预处理数据,并仔细选择算法参数。

相关问题