R语言 逻辑回归模型与混淆矩阵
生活随笔
收集整理的這篇文章主要介紹了
R语言 逻辑回归模型与混淆矩阵
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
邏輯回歸模型(Logistic Regression Model)
建模
邏輯回歸模型是一種 基于線性回歸模型 的分類模型,將回歸(regression)模型數值化(numeric)的優勢用在了分類(classification)上。借助glmnet包,以iris的前100位的兩種花 setosa 和 versicolor 為例
library(glmnet)## 數據處理 data <- iris[1:100,] data$Species <- as.factor(as.numeric(data$Species)-1) n=dim(data)[1] set.seed(12345) id <- sample(1:n, floor(n*0.5)) train <- data[id,] # 訓練集 50% test <- data[-id,] # 測試集 50%## 建模 glm <- glm(formula = Species~., # 以Species為y,其他特征為Xfamily = binomial(link = "logit"), # 適用于邏輯回歸的二項分布data = train) # 訓練集訓練數據## 輸出predication ptrain <- predict(glm, train, type = "response") ptest <- predict(glm, test, type = "response")##總結
以上是生活随笔為你收集整理的R语言 逻辑回归模型与混淆矩阵的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一摞烙饼的排序(搜索树)
- 下一篇: 如何利用fooview实现钉钉自动打卡