📊 AI와 비즈니스 - 엑셀
ChatGPT로 엑셀 조건부 서식 설정하기 - AI 업무 효율화 팁
중요 데이터를 한눈에! AI가 조건에 따라 셀에 색을 입혀 가독성 높은 표를 만드는 방법을 알려드립니다.
대량 데이터에서 패턴 찾기
엑셀에 데이터가 수천, 수만 개 쌓여 있는데... 어디서부터 봐야 할지 막막하시죠? 매출이 오르는 추세인지, 계절별로 패턴이 있는지, 이상한 값은 없는지... 이런 걸 일일이 확인하려면 끝이 없어요.
데이터 속에 숨은 패턴을 찾는 게 바로 데이터 분석의 핵심입니다. 추세를 파악하고, 계절성을 발견하고, 이상치를 감지하고, 변수 간 관계를 찾아내야 의미 있는 인사이트를 얻을 수 있어요.
AI를 활용하면 이런 복잡한 통계 분석을 쉽게 할 수 있습니다. 전문적인 통계 지식이 없어도, "추세를 보여줘", "이상한 값을 찾아줘"라고 하면 AI가 분석 코드를 만들어줘요.
이번 글에서는 AI로 대량 데이터의 패턴을 찾는 방법을 알아봅니다. 시계열 분석, 계절성 발견, 이상치 탐지, 상관관계 분석 등 실무에 필요한 기법들을 다루어볼게요.
1. 시계열 패턴 분석
추세선 분석
AI 프롬프트:
"월별 매출 데이터에서 증가/감소 추세를 분석하고,
다음 달 매출을 예측해주세요."
AI 생성 수식:
// 선형 추세선 (TREND 함수)
=TREND(B2:B13, A2:A13, A14)
// 다항식 추세 (LINEST로 계산)
=LINEST(B2:B13, A2:A13^{1,2,3})
// 이동평균 (3개월)
=AVERAGE(B2:B4)
// 성장률 계산
=(B3-B2)/B2*100
VBA로 추세 분석:
Sub 매출추세분석()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim trend As String
Dim avgGrowth As Double
Dim forecast As Double
Set ws = ThisWorkbook.Sheets("매출데이터")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
' 전월 대비 성장률 계산
ws.Cells(1, 3).Value = "전월대비(%)"
For i = 3 To lastRow
ws.Cells(i, 3).Formula = "=(B" & i & "-B" & i - 1 & ")/B" & i - 1 & "*100"
Next i
' 평균 성장률
avgGrowth = Application.WorksheetFunction.Average( _
ws.Range("C3:C" & lastRow))
' 추세 판단
If avgGrowth > 5 Then
trend = "강한 상승"
ElseIf avgGrowth > 0 Then
trend = "완만한 상승"
ElseIf avgGrowth > -5 Then
trend = "완만한 하락"
Else
trend = "강한 하락"
End If
' 다음 달 예측 (단순 선형)
forecast = ws.Cells(lastRow, 2).Value * (1 + avgGrowth / 100)
' 결과 시트 생성
Dim resultWs As Worksheet
On Error Resume Next
Set resultWs = Sheets("추세분석결과")
If resultWs Is Nothing Then
Set resultWs = Sheets.Add(After:=ws)
resultWs.Name = "추세분석결과"
Else
resultWs.Cells.Clear
End If
On Error GoTo 0
With resultWs
.Cells(1, 1).Value = "매출 추세 분석 보고서"
.Cells(1, 1).Font.Size = 14
.Cells(1, 1).Font.Bold = True
.Cells(3, 1).Value = "분석 기간:"
.Cells(3, 2).Value = ws.Cells(2, 1).Value & " ~ " & ws.Cells(lastRow, 1).Value
.Cells(4, 1).Value = "평균 성장률:"
.Cells(4, 2).Value = Format(avgGrowth, "0.00") & "%"
.Cells(5, 1).Value = "추세:"
.Cells(5, 2).Value = trend
.Cells(6, 1).Value = "최근 매출:"
.Cells(6, 2).Value = Format(ws.Cells(lastRow, 2).Value, "#,##0")
.Cells(7, 1).Value = "다음 달 예측:"
.Cells(7, 2).Value = Format(forecast, "#,##0")
.Columns("A:B").AutoFit
End With
Application.ScreenUpdating = True
MsgBox "추세 분석이 완료되었습니다.", vbInformation
End Sub
2. 계절성 패턴 발견
AI 프롬프트:
"3년간의 월별 매출 데이터에서 계절별 패턴을 찾아주세요.
어느 달이 매출이 높고 낮은지 분석하세요."
AI 생성 VBA:
Sub 계절성분석()
Dim ws As Worksheet
Dim lastRow As Long
Dim monthlyAvg(1 To 12) As Double
Dim monthCount(1 To 12) As Integer
Dim i As Long
Dim month As Integer
Set ws = ThisWorkbook.Sheets("매출데이터")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' 월별 평균 계산
For i = 2 To lastRow
month = Month(ws.Cells(i, 1).Value)
monthlyAvg(month) = monthlyAvg(month) + ws.Cells(i, 2).Value
monthCount(month) = monthCount(month) + 1
Next i
' 평균 계산
For i = 1 To 12
If monthCount(i) > 0 Then
monthlyAvg(i) = monthlyAvg(i) / monthCount(i)
End If
Next i
' 전체 평균
Dim totalAvg As Double
totalAvg = Application.WorksheetFunction.Average( _
ws.Range("B2:B" & lastRow))
' 결과 시트
Dim resultWs As Worksheet
On Error Resume Next
Set resultWs = Sheets("계절성분석")
If resultWs Is Nothing Then
Set resultWs = Sheets.Add(After:=ws)
resultWs.Name = "계절성분석"
Else
resultWs.Cells.Clear
End If
On Error GoTo 0
With resultWs
.Cells(1, 1).Value = "월"
.Cells(1, 2).Value = "평균 매출"
.Cells(1, 3).Value = "지수"
.Cells(1, 4).Value = "특성"
For i = 1 To 12
.Cells(i + 1, 1).Value = i & "월"
.Cells(i + 1, 2).Value = Format(monthlyAvg(i), "#,##0")
' 계절 지수 (평균 대비 비율)
Dim seasonIndex As Double
seasonIndex = monthlyAvg(i) / totalAvg
.Cells(i + 1, 3).Value = Format(seasonIndex, "0.00")
' 특성 분류
If seasonIndex >= 1.2 Then
.Cells(i + 1, 4).Value = "성수기"
.Rows(i + 1).Interior.Color = RGB(146, 208, 80)
ElseIf seasonIndex >= 1.1 Then
.Cells(i + 1, 4).Value = "준성수기"
.Rows(i + 1).Interior.Color = RGB(255, 242, 204)
ElseIf seasonIndex <= 0.8 Then
.Cells(i + 1, 4).Value = "비수기"
.Rows(i + 1).Interior.Color = RGB(255, 199, 206)
Else
.Cells(i + 1, 4).Value = "평년"
End If
Next i
' 차트 생성
Dim chartObj As ChartObject
Set chartObj = .ChartObjects.Add( _
Left:=.Range("F2").Left, _
Top:=.Range("F2").Top, _
Width:=400, _
Height:=300)
With chartObj.Chart
.ChartType = xlColumnClustered
.SetSourceData Source:=resultWs.Range("A1:C13")
.HasTitle = True
.ChartTitle.Text = "월별 계절성 분석"
End With
.Columns("A:D").AutoFit
End With
MsgBox "계절성 분석이 완료되었습니다.", vbInformation
End Sub
3. 이상치(Outlier) 탐지
AI 프롬프트:
"매출 데이터에서 비정상적으로 높거나 낮은 값을 찾아주세요.
통계적 방법(Z-score 또는 IQR)을 사용하세요."
AI 생성 수식:
// Z-score 방법
// C열: Z-score 계산
=ABS((B2-AVERAGE($B$2:$B$1000))/STDEV($B$2:$B$1000))
// D열: 이상치 판정 (|Z| > 2)
=IF(C2>2, "이상치", "정상")
// IQR 방법
// E열: Q1 (25th percentile)
=QUARTILE($B$2:$B$1000, 1)
// F열: Q3 (75th percentile)
=QUARTILE($B$2:$B$1000, 3)
// G열: IQR
=F2-E2
// H열: 이상치 판정
=IF(OR(B2<E2-1.5*G2, B2>F2+1.5*G2), "이상치", "정상")
VBA로 이상치 탐지:
Sub 이상치탐지()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim dataRange As Range
Dim avg As Double
Dim stdDev As Double
Dim zScore As Double
Dim outlierCount As Long
Set ws = ThisWorkbook.Sheets("매출데이터")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Set dataRange = ws.Range("B2:B" & lastRow)
' 통계값 계산
avg = Application.WorksheetFunction.Average(dataRange)
stdDev = Application.WorksheetFunction.StDev(dataRange)
' 헤더
ws.Cells(1, 3).Value = "Z-Score"
ws.Cells(1, 4).Value = "상태"
ws.Cells(1, 5).Value = "편차(%)"
Application.ScreenUpdating = False
For i = 2 To lastRow
' Z-Score 계산
zScore = Abs((ws.Cells(i, 2).Value - avg) / stdDev)
ws.Cells(i, 3).Value = Format(zScore, "0.00")
' 편차 비율
Dim deviation As Double
deviation = (ws.Cells(i, 2).Value - avg) / avg * 100
ws.Cells(i, 5).Value = Format(deviation, "0.00") & "%"
' 이상치 판정 (Z > 2)
If zScore > 2 Then
ws.Cells(i, 4).Value = "이상치"
ws.Rows(i).Interior.Color = RGB(255, 199, 206)
outlierCount = outlierCount + 1
Else
ws.Cells(i, 4).Value = "정상"
ws.Rows(i).Interior.ColorIndex = xlNone
End If
Next i
' 조건부 서식 추가
With ws.Range("C2:C" & lastRow)
.FormatConditions.Delete
.FormatConditions.AddColorScale ColorScaleType:=3
.FormatConditions(1).ColorScaleCriteria(1).FormatColor.Color = RGB(99, 190, 123)
.FormatConditions(1).ColorScaleCriteria(2).FormatColor.Color = RGB(255, 235, 132)
.FormatConditions(1).ColorScaleCriteria(3).FormatColor.Color = RGB(248, 105, 107)
End With
Application.ScreenUpdating = True
MsgBox outlierCount & "개의 이상치가 발견되었습니다." & vbCrLf & _
"평균: " & Format(avg, "#,##0") & vbCrLf & _
"표준편차: " & Format(stdDev, "#,##0"), _
vbInformation
End Sub
4. 상관관계 분석
AI 프롬프트:
"광고비와 매출 간의 상관관계를 분석해주세요.
광고비가 증가하면 매출도 증가하는지 확인하고 싶습니다."
AI 생성 수식:
// 상관계수 (CORREL)
=CORREL(B2:B100, C2:C100)
// 결정계수 R² (RSQ)
=RSQ(B2:B100, C2:C100)
// 회귀분석 기울기
=SLOPE(C2:C100, B2:B100)
// 회귀분석 절편
=INTERCEPT(C2:C100, B2:B100)
// 예측값
=기울기*B2+절편
VBA로 상관관계 분석:
Sub 상관관계분석()
Dim ws As Worksheet
Dim lastRow As Long
Dim xRange As Range, yRange As Range
Dim correlation As Double
Dim rSquared As Double
Dim slope As Double
Dim intercept As Double
Set ws = ThisWorkbook.Sheets("데이터")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Set xRange = ws.Range("B2:B" & lastRow) ' 광고비
Set yRange = ws.Range("C2:C" & lastRow) ' 매출
' 통계 계산
correlation = Application.WorksheetFunction.Correl(xRange, yRange)
rSquared = Application.WorksheetFunction.RSq(xRange, yRange)
slope = Application.WorksheetFunction.slope(yRange, xRange)
intercept = Application.WorksheetFunction.Intercept(yRange, xRange)
' 예측값 계산
ws.Cells(1, 4).Value = "예측 매출"
Dim i As Long
For i = 2 To lastRow
ws.Cells(i, 4).Formula = "=" & slope & "*B" & i & "+" & intercept
Next i
' 잔차 계산
ws.Cells(1, 5).Value = "잔차"
For i = 2 To lastRow
ws.Cells(i, 5).Formula = "=C" & i & "-D" & i
Next i
' 결과 보고서
Dim resultWs As Worksheet
On Error Resume Next
Set resultWs = Sheets("상관관계분석")
If resultWs Is Nothing Then
Set resultWs = Sheets.Add(After:=ws)
resultWs.Name = "상관관계분석"
Else
resultWs.Cells.Clear
End If
On Error GoTo 0
With resultWs
.Cells(1, 1).Value = "광고비 vs 매출 상관관계 분석"
.Cells(1, 1).Font.Size = 14
.Cells(1, 1).Font.Bold = True
.Cells(3, 1).Value = "상관계수 (r):"
.Cells(3, 2).Value = Format(correlation, "0.0000")
.Cells(4, 1).Value = "결정계수 (R²):"
.Cells(4, 2).Value = Format(rSquared, "0.0000")
.Cells(5, 1).Value = "회귀식:"
.Cells(5, 2).Value = "y = " & Format(slope, "#,##0.00") & _
"x + " & Format(intercept, "#,##0.00")
.Cells(7, 1).Value = "해석:"
Dim interpretation As String
If Abs(correlation) >= 0.8 Then
interpretation = "매우 강한 상관관계"
ElseIf Abs(correlation) >= 0.6 Then
interpretation = "강한 상관관계"
ElseIf Abs(correlation) >= 0.4 Then
interpretation = "중간 상관관계"
ElseIf Abs(correlation) >= 0.2 Then
interpretation = "약한 상관관계"
Else
interpretation = "상관관계 없음"
End If
.Cells(7, 2).Value = interpretation
If correlation > 0 Then
.Cells(8, 2).Value = "광고비가 증가하면 매출도 증가하는 경향"
Else
.Cells(8, 2).Value = "광고비가 증가하면 매출이 감소하는 경향"
End If
.Cells(9, 2).Value = "결정계수 " & Format(rSquared * 100, "0.0") & _
"%는 매출 변동의 " & Format(rSquared * 100, "0.0") & _
"%가 광고비로 설명됨을 의미"
.Columns("A:B").AutoFit
End With
' 산점도 생성
Dim chartObj As ChartObject
Set chartObj = resultWs.ChartObjects.Add( _
Left:=resultWs.Range("D2").Left, _
Top:=resultWs.Range("D2").Top, _
Width:=400, _
Height:=300)
With chartObj.Chart
.ChartType = xlXYScatter
.SetSourceData Source:=Union(xRange, yRange)
.HasTitle = True
.ChartTitle.Text = "광고비 vs 매출 산점도"
' 추세선 추가
.SeriesCollection(1).Trendlines.Add( _
Type:=xlLinear, _
DisplayEquation:=True, _
DisplayRSquared:=True).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
End With
MsgBox "상관관계 분석이 완료되었습니다.", vbInformation
End Sub
5. 고객 세분화 (RFM 분석)
AI 프롬프트:
"고객 데이터를 RFM(Recency, Frequency, Monetary) 기준으로
세분화해서 VIP, 일반, 이탈 위험 고객을 분류해주세요."
AI 생성 VBA:
Sub RFM분석()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim today As Date
Dim recency As Long
Dim frequency As Long
Dim monetary As Double
Set ws = ThisWorkbook.Sheets("고객거래내역")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
today = Date
' 고객별 집계 시트
Dim resultWs As Worksheet
On Error Resume Next
Set resultWs = Sheets("RFM분석")
If resultWs Is Nothing Then
Set resultWs = Sheets.Add(After:=ws)
resultWs.Name = "RFM분석"
Else
resultWs.Cells.Clear
End If
On Error GoTo 0
' 헤더
With resultWs
.Cells(1, 1).Value = "고객ID"
.Cells(1, 2).Value = "고객명"
.Cells(1, 3).Value = "최근구매일"
.Cells(1, 4).Value = "R(일)"
.Cells(1, 5).Value = "F(회)"
.Cells(1, 6).Value = "M(원)"
.Cells(1, 7).Value = "R점수"
.Cells(1, 8).Value = "F점수"
.Cells(1, 9).Value = "M점수"
.Cells(1, 10).Value = "RFM점수"
.Cells(1, 11).Value = "고객등급"
End With
Application.ScreenUpdating = False
' 고객별 RFM 계산
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
For i = 2 To lastRow
Dim customerID As String
Dim transDate As Date
Dim transAmount As Double
customerID = ws.Cells(i, 1).Value
transDate = ws.Cells(i, 3).Value
transAmount = ws.Cells(i, 4).Value
If Not dict.Exists(customerID) Then
' 신규 고객
Dim customerData(0 To 3) As Variant
customerData(0) = ws.Cells(i, 2).Value ' 이름
customerData(1) = transDate ' 최근 거래일
customerData(2) = 1 ' 거래 빈도
customerData(3) = transAmount ' 총 구매액
dict.Add customerID, customerData
Else
' 기존 고객
Dim existingData As Variant
existingData = dict(customerID)
' 더 최근 날짜로 업데이트
If transDate > existingData(1) Then
existingData(1) = transDate
End If
existingData(2) = existingData(2) + 1
existingData(3) = existingData(3) + transAmount
dict(customerID) = existingData
End If
Next i
' 결과 시트에 쓰기
Dim rowNum As Long
rowNum = 2
Dim key As Variant
For Each key In dict.Keys
Dim data As Variant
data = dict(key)
resultWs.Cells(rowNum, 1).Value = key
resultWs.Cells(rowNum, 2).Value = data(0)
resultWs.Cells(rowNum, 3).Value = data(1)
' Recency (최근 구매일로부터 경과일)
recency = today - data(1)
resultWs.Cells(rowNum, 4).Value = recency
' Frequency
resultWs.Cells(rowNum, 5).Value = data(2)
' Monetary
resultWs.Cells(rowNum, 6).Value = data(3)
rowNum = rowNum + 1
Next key
lastRow = rowNum - 1
' RFM 점수 계산 (1-5점, 5점이 가장 좋음)
For i = 2 To lastRow
' R 점수 (작을수록 좋음)
recency = resultWs.Cells(i, 4).Value
If recency <= 30 Then
resultWs.Cells(i, 7).Value = 5
ElseIf recency <= 60 Then
resultWs.Cells(i, 7).Value = 4
ElseIf recency <= 90 Then
resultWs.Cells(i, 7).Value = 3
ElseIf recency <= 180 Then
resultWs.Cells(i, 7).Value = 2
Else
resultWs.Cells(i, 7).Value = 1
End If
' F 점수 (많을수록 좋음)
frequency = resultWs.Cells(i, 5).Value
If frequency >= 10 Then
resultWs.Cells(i, 8).Value = 5
ElseIf frequency >= 7 Then
resultWs.Cells(i, 8).Value = 4
ElseIf frequency >= 5 Then
resultWs.Cells(i, 8).Value = 3
ElseIf frequency >= 3 Then
resultWs.Cells(i, 8).Value = 2
Else
resultWs.Cells(i, 8).Value = 1
End If
' M 점수 (많을수록 좋음)
monetary = resultWs.Cells(i, 6).Value
If monetary >= 5000000 Then
resultWs.Cells(i, 9).Value = 5
ElseIf monetary >= 3000000 Then
resultWs.Cells(i, 9).Value = 4
ElseIf monetary >= 1000000 Then
resultWs.Cells(i, 9).Value = 3
ElseIf monetary >= 500000 Then
resultWs.Cells(i, 9).Value = 2
Else
resultWs.Cells(i, 9).Value = 1
End If
' 총 RFM 점수
Dim rfmScore As Integer
rfmScore = resultWs.Cells(i, 7).Value + _
resultWs.Cells(i, 8).Value + _
resultWs.Cells(i, 9).Value
resultWs.Cells(i, 10).Value = rfmScore
' 고객 등급
Dim grade As String
If rfmScore >= 13 Then
grade = "VIP"
resultWs.Rows(i).Interior.Color = RGB(255, 242, 204)
ElseIf rfmScore >= 10 Then
grade = "우수"
resultWs.Rows(i).Interior.Color = RGB(226, 239, 218)
ElseIf rfmScore >= 7 Then
grade = "일반"
ElseIf rfmScore >= 5 Then
grade = "관심필요"
resultWs.Rows(i).Interior.Color = RGB(252, 228, 214)
Else
grade = "이탈위험"
resultWs.Rows(i).Interior.Color = RGB(255, 199, 206)
End If
resultWs.Cells(i, 11).Value = grade
Next i
' 서식 적용
With resultWs
.Range("F2:F" & lastRow).NumberFormat = "#,##0"
.Columns("A:K").AutoFit
.Range("A1:K1").Font.Bold = True
End With
Application.ScreenUpdating = True
' 등급별 통계
Dim vipCount, goodCount, normalCount, careCount, riskCount As Integer
For i = 2 To lastRow
Select Case resultWs.Cells(i, 11).Value
Case "VIP": vipCount = vipCount + 1
Case "우수": goodCount = goodCount + 1
Case "일반": normalCount = normalCount + 1
Case "관심필요": careCount = careCount + 1
Case "이탈위험": riskCount = riskCount + 1
End Select
Next i
MsgBox "RFM 분석이 완료되었습니다." & vbCrLf & vbCrLf & _
"VIP: " & vipCount & "명" & vbCrLf & _
"우수: " & goodCount & "명" & vbCrLf & _
"일반: " & normalCount & "명" & vbCrLf & _
"관심필요: " & careCount & "명" & vbCrLf & _
"이탈위험: " & riskCount & "명", _
vbInformation
End Sub
6. 시장 바구니 분석 (연관규칙)
AI 프롬프트:
"어떤 제품들이 함께 구매되는지 패턴을 찾아주세요.
A 제품을 산 사람이 B 제품도 같이 살 확률을 계산하세요."
AI 생성 VBA:
Sub 장바구니분석()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long, j As Long
Dim products As Object
Dim pairs As Object
Set ws = ThisWorkbook.Sheets("주문내역")
Set products = CreateObject("Scripting.Dictionary")
Set pairs = CreateObject("Scripting.Dictionary")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' 제품 및 조합 빈도 수집
For i = 2 To lastRow
Dim orderID As String
Dim product As String
orderID = ws.Cells(i, 1).Value
product = ws.Cells(i, 2).Value
' 단일 제품 카운트
If products.Exists(product) Then
products(product) = products(product) + 1
Else
products.Add product, 1
End If
' 같은 주문의 다른 제품 찾기
For j = i + 1 To lastRow
If ws.Cells(j, 1).Value = orderID Then
Dim product2 As String
product2 = ws.Cells(j, 2).Value
Dim pairKey As String
If product < product2 Then
pairKey = product & " + " & product2
Else
pairKey = product2 & " + " & product
End If
If pairs.Exists(pairKey) Then
pairs(pairKey) = pairs(pairKey) + 1
Else
pairs.Add pairKey, 1
End If
ElseIf ws.Cells(j, 1).Value <> orderID Then
Exit For
End If
Next j
Next i
' 결과 시트
Dim resultWs As Worksheet
On Error Resume Next
Set resultWs = Sheets("연관분석")
If resultWs Is Nothing Then
Set resultWs = Sheets.Add(After:=ws)
resultWs.Name = "연관분석"
Else
resultWs.Cells.Clear
End If
On Error GoTo 0
' 헤더
resultWs.Cells(1, 1).Value = "제품 조합"
resultWs.Cells(1, 2).Value = "함께 구매 횟수"
resultWs.Cells(1, 3).Value = "지지도"
resultWs.Cells(1, 4).Value = "신뢰도"
Dim rowNum As Long
rowNum = 2
Dim totalOrders As Long
totalOrders = Application.WorksheetFunction.CountA(ws.Range("A:A")) - 1
' 상위 조합 출력
Dim key As Variant
For Each key In pairs.Keys
If pairs(key) >= 3 Then ' 최소 3회 이상
resultWs.Cells(rowNum, 1).Value = key
resultWs.Cells(rowNum, 2).Value = pairs(key)
' 지지도 (전체 거래 대비 비율)
Dim support As Double
support = pairs(key) / totalOrders
resultWs.Cells(rowNum, 3).Value = Format(support, "0.0%")
' 신뢰도 계산
Dim prod1 As String, prod2 As String
prod1 = Split(key, " + ")(0)
Dim confidence As Double
If products.Exists(prod1) Then
confidence = pairs(key) / products(prod1)
resultWs.Cells(rowNum, 4).Value = Format(confidence, "0.0%")
End If
rowNum = rowNum + 1
End If
Next key
' 정렬 (구매 횟수 기준)
With resultWs.Sort
.SortFields.Clear
.SortFields.Add Key:=resultWs.Range("B2:B" & rowNum - 1), _
Order:=xlDescending
.SetRange resultWs.Range("A1:D" & rowNum - 1)
.Header = xlYes
.Apply
End With
resultWs.Columns("A:D").AutoFit
MsgBox "장바구니 분석이 완료되었습니다.", vbInformation
End Sub
7. 패턴 요약 대시보드
통합 분석 매크로:
Sub 종합패턴분석()
Dim startTime As Double
startTime = Timer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
' 1. 추세 분석
Call 매출추세분석
' 2. 계절성 분석
Call 계절성분석
' 3. 이상치 탐지
Call 이상치탐지
' 4. 상관관계 분석
Call 상관관계분석
' 5. RFM 분석
Call RFM분석
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Dim elapsed As Double
elapsed = Timer - startTime
MsgBox "종합 패턴 분석이 완료되었습니다." & vbCrLf & _
"소요 시간: " & Format(elapsed, "0.0") & "초", _
vbInformation
End Sub
마무리
AI로 데이터 패턴 찾기:
- ✅ 시계열 추세 및 계절성 분석
- ✅ 통계적 이상치 탐지
- ✅ 변수 간 상관관계 발견
- ✅ 고객 세분화 및 연관규칙 분석
다음 글에서는 이러한 분석을 활용한 재무 예측 모델을 만들어봅니다.