4. 1. 머신러닝 개요 – 적용 분야
기계학습(Machine Learning)
패턴・규칙・관계 등과 같은 특징을 추출하여 규칙을 생성
기계학습(Machine Learning)
패턴・규칙・관계 등과 같은 특징을 추출하여 규칙을 생성
기계기계 사람사람 교통교통 자동차자동차 정보 시스템정보 시스템의료의료
검색검색 분류분류 판별판별 감지감지 예측예측
추론추론 판단판단최적화최적화
의사결정의사결정 기기 제어기기 제어어드바이스어드바이스
5. 1. 머신러닝 개요 – 모델 훈련
예측모델
생성 단계
과거데이
터
기계학습
(예측
모델링)
예측 모델
예측모델
적용단계
신규데이
터
예측 모델
예측 결과
(예측점수)
6. 1. 머신러닝 개요 – 훈련된 모델 적용
예측모델
생성단계
과거데이
터
기계학습
(예측
모델링)
예측 모델
예측모델
적용단계
신규데이
터
예측 모델
예측 결과
(예측점수)
UiPath + ML 모델
8. 2. 테스트 데이터 및 시나리오 – 데이터
- R ggplot2 패키지에 포함된 53,940개의 다이어몬드 가격 정보
9. 2. 테스트 데이터 및 시나리오 – 데이터
- 가격(price)을 포함한 10개의 필드
1. 캐럿(carat) – 다이아몬드의 무게
2. 컷(cut) – 절삭면 상태 : Fair, Good, Very Good, Premium, Ideal
3. 색(color) – 다이아몬드 색 : J(최하) < I < H < G < F < E < D(최상)
4. 투명도(clarity) – I1(최하), SI2, SI1, VS2, VS1, VVS2, VVS1, IF (최상)
5. 깊이(depth) – 윗면의 가로,세로 대비 높이 : 2 * z / (x + y) (43--79)
6. 테이블(table) – 직경 대비 평평한 부분 비율 : (43 – 95)
7. 가격(price) – US 달러 표시 가격 ( $326 ~ $18,823 )
8. X – 밀리미터 단위 길이 : ( 0 ~10.74)
9. Y – 밀리미터 단위 너비 : ( 0 ~ 58.9 )
10. Z – 밀리미터 단위 깊이 : ( 0 ~ 31.8 ) 예측 대상
10. 2. 테스트 데이터 및 절차 – 절차
1. 데이터 준비 ( 훈련 데이터 + 테스트 데이터 )
2. 모델 선택 ( RandomForestRegressor 사용 )
3. Python 머신러닝 모델 훈련 및 결과 저장
4. 저장된 모델 UiPath 디렉토리로 복사
5. Python 모델을 수행하는 UiPath Flowchart 수행
6. 수행 결과 확인 ( Excel + eMail )
12. 3. 코드 Review – 모델 훈련 python 코드
import pandas
import pickle
from sklearn import model_selection
from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import LabelEncoder
# 훈련 데이터 읽기
in_url = "train_dia.csv"
dataframe = pandas.read_csv(in_url)
categorical_features = ['cut', 'color', 'clarity']
le = LabelEncoder()
# 데이터 정제 ( numerical 변환 )
for i in range(3):
new = le.fit_transform(dataframe[categorical_features[i]])
dataframe[categorical_features[i]] = new
array = dataframe.values
X = array[:,0:6]
Y = array[:,6]
# 훈련/테스트 데이터 분할 및 훈련
X_train, X_test, Y_train, Y_test = model_selection.train_test_split(X, Y,
test_size=0.33, random_state=7)
model = RandomForestRegressor(n_estimators = 50, max_depth =
10, random_state = 101)
model.fit(X_train, Y_train)
# 훈련 결과 확인
result = model.score(X_test, Y_test)
print(result)
# 훈련된 모델 저장
filename = 'model_50.sav'
pickle.dump(model, open(filename, 'wb'))
훈련된 모델
저장 파일
13. 3. 코드 Review – 훈련된 모델 수행을 위한 python 코드
# 호출할 Python Method
def pricePrediction(in_file, modelFile ) :
import os
import pandas
import pickle
from sklearn.preprocessing import LabelEncoder
# 예측 대상 데이터 읽어오기
os.chdir("C:testData")
myData = pandas.read_csv(in_file)
categorical_features = ['cut', 'color', 'clarity']
le = LabelEncoder()
# 데이터 정제 ( numerical 변환 )
for i in range(3):
newValue = le.fit_transform(myData[categorical_features[i]])
myData[categorical_features[i]] = newValue
array = myData.values
X = array[:,0:6]
# 훈련된 모델 가져오기
loaded_model = pickle.load(open(modelFile, 'rb'))
Y_pred = loaded_model.predict(X).astype(int)
# 예측 결과 파일 저장
out_file = in_file.split('.')[0] + "_pred_price.csv"
myData['pred_price'] = pandas.Series(Y_pred,
index=myData.index)
myData.to_csv( out_file )
예측할 대상 파일
훈련된 모델 불러오기
가격 예측
예측 결과 csv 파일로 저장
호출할 method
15. 3. 코드 Review – UiPath FlowChart : 테스트 데이터 입력
예측할 대상 입력 받음
16. 3. 코드 Review – UiPath FlowChart : 훈련된 모델 입력
훈련된 모델이 저장된 파일
( 예 : “model_50.sav” )
17. 3. 코드 Review – UiPath FlowChart : 예측 모델 수행
- python scope Load Python Script Invoke Python Script Get Python Object
18. 3. 코드 Review – UiPath FlowChart : 예측 모델 수행
- python scope 설정
Python.exe 가 존재하는 디렉토리
Python 버젼32bit(x86) 혹은 64비트(x64)
19. 3. 코드 Review – UiPath FlowChart : 예측 모델 수행
- Load Python Script 설정
수행할 python 스크립트 ( 예 : “c:myModelrunModel.py” )
UiPath 객체화된 python 스크립트
20. 3. 코드 Review – UiPath FlowChart : 예측 모델 수행
- Invoke Python Script 설정
Python 스크립트 수행을 위한 입력 변수
( 예 : { test_data_file, trained_model_file } )
Load Python Script 에서
UiPath 객체화 된 python 스크립트
Python 객체 내의 호출하는 method
( 예 : “pricePrediction” )
Python 메서드에서
반환한 python 객체
21. 3. 코드 Review – UiPath FlowChart : 예측 모델 수행
- Get Python Object 설정
Python 메서드에서 반환한 python 객체
UiPath 객체로 변환된 객체
22. 3. 코드 Review – UiPath FlowChart : 결과 메일 전송
전송자의 email 주소, password
( 예 : “ksw@mailserver.com”, “password” )수신자의 email 주소, 제목, 본문
송신 메일 서버 정보 ( 예 : “smtp.gmail.com“) 송신 메일 서버 포트 ( 예 : 465 )
첨부 파일명
23. 3. 코드 Review – UiPath FlowChart : 예측 결과 확인
명령 수행시 입력값
( 예 : “predicted.csv”)
수행할 명령
(예 : "C:Program FilesMicrosoft
OfficerootOffice16EXCEL.EXE“ )
명령 수행 디렉토리
( 예 : “c:testDir” )