[R] lm함수를 통한 선형 회귀, 분할 정복을 통한 선형 회귀
2023. 10. 21. 18:29ㆍR, 빅데이터 분석 실험
1. lm 함수로 구하기
setwd('/Users/bagjeong-yong/desktop/bigdataA/data')
data1 <- read.csv('data1.csv',header=TRUE)
data2 <- read.csv('data2.csv',header=TRUE)
data3 <- read.csv('data3.csv',header=TRUE)
data<-rbind(data1,data2,data3)
y =as.numeric(data[,1])
n = length(y)
x = as.matrix(cbind(rep(1,n),data[,2:5]))
lm(y~x)
해당 결과를 확인 할 수 있다.
A = matrix(0,5,5)
B = matrix(0,5,1)
setwd('/Users/bagjeong-yong/desktop/bigdataA/data')
data1 <- read.csv('data1.csv',header=TRUE)
y =as.numeric(data1[,1])
n = length(y)
x = as.matrix(cbind(rep(1,n),data1[,2:5]))
A = A + t(x) %*% x
B = B + t(x) %*% y
data2 <- read.csv('data2.csv',header=TRUE)
y = as.numeric(data2[,1])
n = length(y)
x = as.matrix(cbind(rep(1,n),data2[,2:5]))
A = A + t(x) %*% x
B = B + t(x) %*% y
data3 <- read.csv('data3.csv',header=TRUE)
y =as.numeric(data3[,1])
n = length(y)
x = as.matrix(cbind(rep(1,n),data3[,2:5]))
A = A + t(x) %*% x
B = B + t(x) %*% y
r = solve(A) %*% B
r
값이 동일 함을 확인 할 수 있다.
'R, 빅데이터 분석 실험' 카테고리의 다른 글
massive data는 어떻게 선형회귀분석을 적용할까? (1) | 2023.10.21 |
---|---|
linear regression analysis (1) | 2023.10.21 |
[R] 기본 문법 및 주요 함수 (1) | 2023.10.21 |
빅데이터 문제 해결 방법 (0) | 2023.10.21 |
빅데이터 기초 지식 (1) | 2023.10.21 |