728x90

SAS, R, Python 으로 하는 간단한 회귀분석 프로그램입니다.

 

[SAS 프로그램]

DATA a1;INFILE 'D:\sas_class\simple.csv' DLM=",";
INPUT gender $ wei hei age join $10.;
PROC REG;MODEL wei=hei;
RUN;

 

[R 프로그램]

setwd("d:/sas_class")
a1 <- read.csv("simple.csv")
names(a1) <- c("gender","wei","hei","age","join")
a1
model_out <- lm(wei~hei,data=a1)  # stats 패키지의 lm 함수를 이용
summary(model_out)

 

[Python 프로그램]

import pandas as pd   # Pandas 라이브러리 불러오기
import numpy as np   # 넘파이 라이브러리 불러오기
from sklearn.linear_model import LinearRegression
wei = [65, 66,  69, 67, 68, 72, 65, 66, 69, 67, 68, 72]
hei = [171,172,176,173,177,178,171,172,176,173,177,178]
age = [ 23, 24, 38, 43, 40, 42, 23, 24, 38, 43, 40, 42]
X = np.array(hei) 
X=X.reshape(12,1)  # 넘파이 배열
y= np.array(wei)
y=y.reshape(12,1)  # 넘파이 배열

model_out= LinearRegression(fit_intercept=True)  # 사이킷런에 있는 LinearRegression 함수를 이용
model_out.fit(X,y) # 회귀분석 실행
print(model_out.intercept_[0],model_out.coef_[0])

+ Recent posts