인류의 복지와 편익을 위한 인프라 건설을 주도하는토목공학과
제목
(3학년) 인공지능개발실습 기말고사 대비(예상문제, 코딩, 데이터)_박영훈 교수
작성일
2022.06.07
작성자
부천대학교 토목과
# 머신러닝_단순회귀분석 cars=read.csv("cars_2022.csv") head(cars) out=lm(dist~speed, data=cars) summary(out) out_0=lm(dist~speed+0, data=cars) summary(out_0) new=data.frame(speed=27) predict(out_0, new, interval = "confidence") predict(out_0, new, interval = "prediction") # 머신러닝_다중 회귀분석 salary=read.csv("salary_2022.csv") head(salary) model=lm(salary~experience+score, data=salary) summary(model) predict(model, data.frame("experience"=c(9,8), "score"=c(85,90)), interval="confidence") # 머신러닝_판별분석 turkey=read.csv("turkey.csv") head(turkey, n=20) turkey=na.omit(turkey) head(turkey, n=20) install.packages("MASS") library(MASS) model_lda=lda(TYPE~HUM+ULN, data=turkey) model_lda predict(model_lda,data.frame("HUM"=c(140,145), "ULN"=c(145,135))) model_qda=qda(TYPE~HUM+ULN, data=turkey) model_qda predict(model_qda,data.frame("HUM"=c(140,145), "ULN"=c(145,135))) #머신러닝_신경망분석 install.packages("nnet") library(nnet) cb=read.delim("Hshopping.txt", stringsAsFactors = FALSE) head(cb,n=20) str(cb) cb$성별=as.factor(cb$성별) cb$출연자=as.factor(cb$출연자) cb$반품여부=as.factor(cb$반품여부) str(cb) install.packages("caret", dependencies = TRUE) library(caret) set.seed(1) inTrain=createDataPartition(y=cb$반품여부, p=0.6, list=FALSE) cb.train=cb[inTrain,] cb.test=cb[-inTrain,] set.seed(1234567) nn_model=nnet(반품여부~성별+나이+구매금액+출연자, data=cb.train, size=7, maxit=1000) install.packages("NeuralNetTools") library(NeuralNetTools) garson(nn_model) predicted=as.factor(predict(nn_model, newdata=cb.test, type="class")) confusionMatrix(predicted,cb.test$반품여부)