关于数据挖掘:R语言使用逻辑回归Logistic单因素方差分析anova和数据可视化分类iris鸢尾花数据集

7次阅读

共计 3299 个字符,预计需要花费 9 分钟才能阅读完成。

全文链接:http://tecdat.cn/?p=27650 

摘要

本文将探讨 Fisher 和 Anderson 鸢尾花数据集中出现的三个变量之间的关系,特地是 virginica 和 versicolor 级别的因变量变量 物种 对预测变量 花瓣长度 花瓣宽度 的逻辑回归。单因素方差分析和数据可视化都确定了因变量的一个因素程度,即 I. setosa,很容易与其余两个因素线性拆散,具备非常明显的均值和方差,因而不是咱们对逻辑回归感兴趣。

介绍

对鸢尾花数据的初步查看引发了对于数据集自身性质的间接问题:为什么要收集如此简略的数据,事实上,咱们最后的直觉之一是想晓得,鉴于数据集中的信息,是否有可能在进行相干剖析和诊断后,建设一个可能对新察看后果进行分类的模型。

咱们很诧异也很快乐得悉数据集通常是为了这个目标剖析的。它最常见的用处是机器学习,特地是分类和模式识别利用。咱们开始应用到目前为止所学的工具查看局部数据——即,咱们将应用逻辑回归和两种鸢尾花,Virginica 和 versicolor(别离示意为 π =0 和 π =1)。第三种物种 I. setosa 被排除在外,因为它在所有维度上都与其余两个物种高度拆散。

办法

在这种状况下,逻辑回归比卡方或 Fisher 准确测验更适合,因为咱们有一个二元因变量和多个预测变量,它还容许咱们在管制其余变量的同时分明地量化各种影响的强度(即每个参数的劣势比)。

plot(predicresiduals(logit.fylab="

rl=lm(resi.fit)~bs(predict(.fit),8))

#rl=loess(repredictit.fit))

y=pree=TRUE)

segments(predict(l

后果

创立了一个逻辑模型,个别模型和参数特色如下:

通过查看它们的劣势比,能够无效地总结参数估计的含意。显然,截距项并不是特地乏味,因为数据点 (0,0) 在实践上是不可能的,而且远远超出了咱们收集的数据范畴。_β1_的劣势比和_β2_ 更乏味;它们别离代表相干变量的每一个增量,而另一个放弃不变时,特定动物属于 I. virginica 物种的几率减少。在这种状况下,很显著,减少花瓣宽度会对特定动物被归类为 I. virginica 的几率产生微小影响——这种影响大概是花瓣长度的 110 倍。然而,劣势比 95% 置信区间都不蕴含 1,因而咱们能够得出结论,这两种效应都具备统计学意义。

library(ggplot2)



#绘图数据

qplot(Petal.Width, Petal.Length, colour = Species,  data = irises, main = "Iris classification")

应用模型中的系数预计,咱们能够确定一个规范——一个线性判别式——通过它咱们能够最好地拆散数据。线性判别式的准确度在以下混同矩阵中给出:

# 从模型中取得预测后果

logit.predictions <- ifelse(predict(logit.fit) > 0,'virginica', 'versicolor')



# 混同矩阵 

table(irises\[,5\],logit.predictions)

诊断

通过查看残差和数据的影响,咱们确定了几个潜在的异样察看后果:

在所有可能有问题的察看中,咱们留神到第 57 个察看样本可能是异样点。查看诊断图,咱们看到逻辑回归的趋势特色,包含残差与预测图中的两条不同曲线。第 57 个察看样本呈现在每个诊断图中,但侥幸的是没有超过库克的间隔。

论断与探讨

在这种状况下,逻辑模型的应用具备启发性,因为它显示了依据多个预测变量将数据分类为二元因变量技术的弱小性能。该模型可预感地显示出最大的不确定性,即在给定维度(即一个物种的数据与另一个物种的数据之间的边界)中观测值靠近平均值时。思考模型是否能够改良,或者不同的模型是否更适宜数据是很乏味的;兴许对于这个分类问题,k- 最近邻办法是必要的。无论如何,6% 的谬误分类率实际上是相当不错的;更多的数据必定会进步这个数字。

自测题

Diagnosis of Depression in Primary Care
To study factors related to the diagnosis of depression in primary care, 400 patients were randomly selected and the following variables were recorded:
DAV: Diagnosis of depression in any visit during one year of care.
0 = Not diagnosed
1 = Diagnosed
PCS: Physical component of SF-36 measuring health status of the patient.
MCS: Mental component of SF-36 measuring health status of the patient
BECK: The Beck depression score.
PGEND: Patient gender
0 = Female
1 = Male
AGE: Patient’s age in years.
EDUCAT: Number of years of formal schooling.
The response variable is DAV (0 not diagnosed, 1 diagnosed), and it is recorded in the first column of the data. The data are stored in the file final.dat and is available from the course web site. Perform a multiple logistic regression analysis of this data using SAS or any other statistical packages. This includes
estimation, hypothesis testing, model selection, residual analysis and diagnostics. Explain your findings in a 3 to 4- page report. Your report may include the following sections:
• Introduction: Statement of the problem.
• Material and Methods: Description of the data and methods that you used for the analysis.
• Results: Explain the results of your analysis in detail. You may cut and paste some of your computer
outputs and refer to them in the explanation of your results.
• Conclusion and Discussion: Highlight the main findings and discuss.
Please cut and paste the computer outputs to your report and do not include any direct computer output as an attachment
Please note that you have also the option of using a similar data set in your own field of interest.


 

最受欢迎的见解

1.R 语言多元 Logistic 逻辑回归 利用案例

2. 面板平滑转移回归 (PSTR) 剖析案例实现剖析案例实现 ”)

3.matlab 中的偏最小二乘回归(PLSR)和主成分回归(PCR)

4.R 语言泊松 Poisson 回归模型剖析案例

5.R 语言回归中的 Hosmer-Lemeshow 拟合优度测验

6.r 语言中对 LASSO 回归,Ridge 岭回归和 Elastic Net 模型实现

7. 在 R 语言中实现 Logistic 逻辑回归

8.python 用线性回归预测股票价格

9.R 语言如何在生存剖析与 Cox 回归中计算 IDI,NRI 指标

正文完
 0