본문 바로가기
AZ ml

신용위험 예측 기계학습 모델 만들기 (4)

by EasyGPT 2016. 1. 13.
반응형

Binary Classfication: Credit risk prediction 이진 분류: 신용위험 예측

 

Microsoft published on September 2, 2014

Open in Studio

PublishedSeptember 2, 2014

Last updatedAugust 14, 2015

Report Abuse

Summary 요약

This sample demonstrates how to perform cost-sensitive binary classification in Azure ML Studio to predict credit risk based on information given on a credit application.
샘플은 신용 응용프로그램에 주어진 정보를 바탕으로 신용위험을 예측하는 애저 ML Studio에서 비용에 민감한 이진 분류를 수행하는 방법을 보여줍니다.

Description

Binary Classification: Credit Risk Prediction 이진 분류: 신용위험 예측

This sample demonstrates how to perform cost-sensitive binary classification in Azure ML Studio to predict credit risk based on the information given on a credit application. The classification problem in this experiment is a cost-sensitive one because the cost of misclassifying the positive samples is five times the cost of misclassifying the negative samples.
샘플은 신용 응용프로그램에 주어진 정보를 바탕으로 신용 위험을 예측하는 애저 ML Studio에서 비용에 민감한 이진 분류를 수행하는 방법을 보여줍니다. 긍정적 샘플로 잘못 분류함에 따른 비용은 부정적 샘플로 잘못 분류함에 따른 비용 5배이기 때문에, 실험에서 분류 문제는 비용에 민감한 것입니다.

In this experiment, we compare two different approaches for generating models to solve this problem:
실험에서는 문제를 해결하기 위하여 모델을 생성하는 2개의 서로 다른 방식을 비교합니다

  • Training using the original data set 데이터집합을 사용한 훈련
  • Training using a replicated data set 복제된 데이터집합을 사용한 훈련

In both approaches, we evaluate the models using the test data set with replication, to ensure that results are aligned with the cost function. We test two classifiers in both approaches: Two-Class Support Vector Machine and Two-Class Boosted Decision Tree.
방식에서, 결과가 비용함수(cost function) 통일되도록 하기 위하여, 복제를 가진 테스트용 데이터집합을 사용한 모델을 평가 합니다. 가지 방식으로 2개의 분류기를 테스트합니다: Two-Class Support Vector Machine Two-Class Boosted Decision Tree.

 

Data 데이터

We use the German Credit Card data set from the UC Irvine repository.
UCI Irvine 리포지토리의 German Credit Data 사용합니다.

 

This data set contains 1000 samples with 20 features and 1 label. Each sample represents a person. The 20 features include both numerical and categorical features. The last column is the label, which denotes the credit risk and has only two possible values: high credit risk = 2, and low credit risk = 1.
데이터집합에는 20개의 특성과 1개의 레이블을 가진 1000개의 샘플이 있습니다. 샘플은 각각의 사람입니다.  20개의 특성은 숫자 특성과 범주 특성으로 되어 있습니다. 마지막 (column) 레이블인데, 이 레이블은 신용위험을 의미하며 오직 2개의 값만 가질 수 있습니다: 높은 신용위험 = 2, 낮은 신용위험 = 1.

The cost of misclassifying a low risk example as high is 1, whereas the cost of misclassifying a high risk example as low is 5.
낮은 위험 예제를 높은 위험으로 잘못 분류할 때의 비용이 1이면, 높은 위험 예제를 낮은 위험으로 잘못 분류할 때의 비용은 5입니다.

 

http://az712634.vo.msecnd.net/samplesimg/v1/5/whole_exp.png

Data Processing 데이터 처리

We started by using the Metadata Editor module to add column names to replace the default column names with more meaningful names, obtained from the data set description on the UCI site. The new column names are provided as comma-separated values in the New column name field of Metadata Editor.
먼저 UCI site 데이터집합 서술로부터 확보된, 기본 이름을 보다 의미 있는 이름으로 바꾸 위하여 컬럼 이름을 추가하기 위하여 Metadata Editor 모듈을 사용합니다. 새로운 컬럼 이름을 Metadata Editor New column name 필드 안에 쉼표-분리 값으로 제공합니다.

Next, we generated training and test sets used for developing the risk prediction model. We split the original data set into training and test sets of the same size using the Split module.
다음에 위험예측모델 개발에 사용될 훈련용 테스트용 데이터집합을 생성합니다. Split모듈을 사용해서 원본데이터를 훈련용 세트와 테스트용 세트로 분리합니다.

To create sets of equal size, we set the option, Fraction of rows in the first output, to 0.5.

 

Generating the New Data Set 새로운 데이터집합 생성하기

Because the cost of underestimating risk is high in the real world, we set the cost of misclassification as follows:
현실 세계에서 위험을 저평가할 때의 비용이 높기 때문에, 분류의 비용을 아래와 같이 설정합니다:

  • For high risk cases misclassified as low risk: 5 고위험 케이스를 저위험으로 잘못 분류한 경우: 5
  • For low risk cases misclassified as high risk: 1 저위험 케이스를 고위험으로 잘못 분류한 경우: 1

To reflect this cost function, we generated a new data set, in which each high risk example is replicated five times, whereas the number of low risk examples are kept as is.
비용함수를 반영하여, 새로운 데이터집합을 생성하였는데, 고위험 예제는 5 복제된 반면, 저위험 예제는 그대로 입니다

We split the data into training and test data sets before replication to prevent the same example from being in both the training and test sets.

To replicate the high risk data, we put the following R code into an Execute R Script module:

 

dataset <- maml.mapInputPort(1)
data.set <- dataset[dataset[,21]==1,]
pos <- dataset[dataset[,21]==2,]
for (i in 1:5) data.set <- rbind(data.set,pos)
row.names(data.set) <- NULL 
maml.mapOutputPort("data.set")

 

Both the training and test data sets are replicated using the Execute R Script module.
Finally, we used the Descriptive Statistics module to compute statistics for all fields of the input data.
최종적으로 input 데이터의 모든 필드들에 대한 통계를 계산하기 위하여 Descriptive Statistics 모듈을 사용하였습니다.

Feature Engineering 특성 엔지니어링

One of the machine learning algorithms requires that data be normalized. Therefore, we used the Normalize Data module to normalize the ranges of all numeric features, using a tanh transformation. A tanh transformation converts all numeric features to values within a range of 0-1, while preserving the overall distribution of values.
어떤 ML 알고리즘은 데이터의 정규화를 요구합니다. 따라서 모든 숫자 특성의 범위를 정규화하기 위하여, tanh 변형을 사용한 Normalize Data 모듈을 사용하였습니다. tanh 변형은 모든 숫자 특성을 0-1 범위 내의 값으로 변환하는데, 값들의 전반적 분포를 보전합니다.

The Two-Class Support Vector Machine module handles string features for us, converting them to categorical features and then to binary features having a value of 0 or 1, so there is no need to normalize these features.
Two-Class Support Vector Machine
모듈, 문자열을 범주 특성으로 변환함으로써 그리고 0 또는 1 값을 가진 바이너리 특성으로 변환함으로써, 문자 특성을 처리하는데, 따라서 이들 특성은 정규화할 필요가 없습니다.

Model 모델

In this experiment, we applied two classifiers: Two-Class Support Vector Machine (SVM) and Two-Class Boosted Decision Tree. Because we also used two datasets, we generated a total of four models:
실험에서, 2개의 분류기: Two-Class Support Vector Machine (SVM) Two-Class Boosted Decision Tree 적용하였습니다. 또한 2개의 데이터집합을 사용하였기 때문에, 4개의 모델 생성되었습니다:

  • SVM, trained with original data
  • SVM, trained with replicated data
  • Boosted Decision Tree, trained with original data
  • Boosted Decision Tree, trained with replicated data

We used the standard experimental workflow to create, train, and test the models:
모델들을 생성하고, 훈련시키고, 테스트하기 위하여 표준 실험 워크플로우를 사용하였습니다:

1.       Initialize the learning algorithms, using Two-Class Support Vector Machine and Two-Class Boosted Decision Tree
Two-Class SVM
 
 Two-Class Boosted Decision Tree 사용하여 학습 알고리즘을 초기화

2.       Use Train Model to apply the algorithm to the data and create the actual model.
알고리듬을 데이터에 적용하고 실제 모델을 생성하기 위하여 Train Model 사용

3.       Use Score Model to produce scores using the test examples.
테스트 예제를 사용하여 점수를 산출하기 위하여 Score Model 사용

The following diagram shows a portion of this experiment, in which the original and replicated training sets are used to train two different SVM models. Train Model is connected to the training set, whereas Score Model is connected to the test set.
아래 다이어그램은 실험의 일부를 보여주고 있는데, 원본과 복제된 훈련용 세트가 2개의 서로 다른 SVM 모델들 훈련시키는데 사용되고 있습니다. Train Model 훈련용 세트와 연결되어 있고, Score Model 테스트 세트 연결되어 있습니다.

 

http://az712634.vo.msecnd.net/samplesimg/v1/5/train_flow.png

 

In the evaluation stage of the experiment, we computed the accuracy of each of the four models. For this experiment, we've used Evaluate Model to compare examples that have the same misclassification cost.
실험의 평가단계에서, 4 모델의 각각의 정확도를 계산했습니다. 실험에서, 동일한 분류 비용을 가진 예제 들을 비교하기 위하여 Evaluate Model 사용했습니다.

The Evaluate Model module can compute the performance metrics for up to two scored models. Therefore, we used one instance of Evaluate Model to evaluate the two SVM models, and another instance of Evaluate Model to evaluate the two boosted decision tree models.
Evaluate Model
모듈은 최대 2개의 채점된 모델까지 performance metrics 계산할 있습니다. 따라서, SVM 모델들을 평가하기 위하여 1개의 Evaluate Model 인스턴스를 사용했고, 2개의 boosted decision tree모델들을 평가하기 위하여 다른 Evaluate Model 인스턴스를 사용했습니다.
Notice that the replicated test data set is used as the input for Score Model. In other words, the final accuracy scores include the cost for getting the labels wrong.
복제된 테스트용 데이터집합은 Score Model input으로 사용됨을 알아야 합니다. 다른 말로 최종 정확도 점수에는 getting the labels wrong 대한 비용이 포함됩니다.

Combine Multiple Results  여러 결과를 결합하기

The Evaluate Model module produces a table with a single row that contains various metrics. To create a single set of accuracy results, we first used Add Rows to combine the results into a single table, and then used the following simple R script in the Execute R Script module to add the model name and training approach for each row in the table of results.
Evaluate Model 
모듈은 다양한 메트릭이 포함된 단일 행을 가진 표를 생성합니다. 세트의 정확한 결과를 생성하기 위하여, 결과들을 단일 표로 묶는 Add Rows 사용하였고, Execute R Script 모듈 안에서 다음의 간단한 R스크립트 사용하여 모델 이름을 추가하였고, 결과 안의 행에 대한 훈련방식을 사용하였습니다.

 

dataset <- maml.mapInputPort(1)
a <- matrix(c("SVM","weighted",
              "SVM","unweighted",
              "Boosted Decision Tree","weighted",
              "Boosted Decision Tree","unweighted"),
            nrow=4,ncol=2,byrow=T)
data.set <- cbind(a,dataset)            
names(data.set)[1:2] <- c("Algorithm","Training")
maml.mapOutputPort("data.set")

 

Finally we removed the columns with non-relevant metrics using the Project Columns module.
최종적으로 Project Columns 모듈을 사용하여 관련성이 없는 메트릭을 가진 열을 제거하였습니다.

Results 결과

To view the final results of the experiment, you can right-click the Visualize output of the last Project Columns module.
실험의 최종결과를 보기 위하여, 최종 Project Columns 모듈의 Visualize output -클릭할 있습니다.

  • The first column lists the machine learning algorithm used to generate a model.
    첫째 열은 모델 생성에 사용된 ML 알고리듬 보여줌
  • The second column indicates the type of the training set.
    둘째 열은 훈련용 세트의 타입 가리킴
  • The third column contains the cost-sensitive accuracy value.
    셋째 열은 비용-민감 정확도 포함하고 있음

http://az712634.vo.msecnd.net/samplesimg/v1/5/accuracy_comparison.png

 

From these results, you can see that the best accuracy is provided by the model that was created using Two-Class Support Vector Machine and trained on the replicated training data set.
이들 결과로부터, Two-Class SVM 사용하여 생성되고, 복제된 훈련용 데이터집합에서 훈련된 모델이 최고의 정확도를 제공하는 것을 봅니다.


 

반응형

댓글