当前位置: 首页 > news >正文

重庆网站建设推广怎样在百度上发布免费广告

重庆网站建设推广,怎样在百度上发布免费广告,网站自己做的记者证,哪里有网站建设哪家好一、线性回归分析 1、lm()函数 lm()函数是用于拟合线性模型(Linear Models)的主要函数。线性模型是一种统计方法,用于描述一个或多个自变量(预测变量、解释变量)与因变量(响应变量)之间的关系…

一、线性回归分析

1、lm()函数

lm()函数是用于拟合线性模型(Linear Models)的主要函数。线性模型是一种统计方法,用于描述一个或多个自变量(预测变量、解释变量)与因变量(响应变量)之间的关系。它可以处理简单的线性回归、多元线性回归以及带有分类预测变量的回归(通过创建虚拟变量或指示变量)。

基本格式:

lm(formula, data, subset, weights, ...)

  1. formula:描述因变量与自变量间关系的符号表达式。
  2. data:包含公式中所有变量的数据框(data frame)或列表(list)。若未明确指定,R 将在全局环境中搜索变量。
  3. subset(子集):逻辑向量或表达式,用于从数据中筛选用于模型拟合的观测值。默认为NULL,即使用全部数据。
  4. weights(权重):可选参数,用于为各观测值分配权重。默认为 NULL,即所有观测值权重相等。
  5. ...(其他参数):lm函数还接受其他多个参数,这些参数通常与模型的拟合与优化相关。例如,na.action参数可用于定义缺失值(NA)的处理方式,method参数可用于指定拟合方法(尽管对于普通线性模型,此参数通常设为默认值 "qr" 即可)。

2、简单线性回归

用R语言内置的cars数据集做演示,此数据集记录了汽车的速度(speed)和停车距离(dist),一共50条记录。

head(cars, n=5)
# 简单线性模型拟合
fit <- lm(dist ~ speed, data=cars)
# 拟合结果的详细信息
summary(fit)

# 模型参数
coeffcients(fit)
# 回归系数置信区间
confint(fit)
# 模型预测值
fitted(fit)
# 模型的残差
residuals(fit)

 从上面结果可知,拟合得到的模型参数的截距项为-17.5791,回归系数是3.9324,调整的多重R2(Adjusted R-squared)为0.6438,说明该模型能解释停车距离为64.38%的变异。方差分析结果也显示整个模型是显著的(p=1.49e-12 < 0.05)。因为简单线性回归只有一个自变量,所以模型的F检验和回归系数的t检验的结果是相同的。

plot(cars)
lines(x=cars$speed, y=fitted(fit), col="red")

3、多重线性回归

多重线性回归包含多个自变量。

下面使用R语言内置的数据集mtcars进行演示,此数据集包含了32种汽车的11种基本性能数据。通过汽车排量(disp),总功率(hp),后桥速比(drat)和车重(wt)四个变量来预测汽车油耗指数(mpg),mpg越大,油耗越低。

head(mtcars, n=5)
fit <- lm(mpg ~ disp + hp + drat + wt, data=mtcars)
summary(fit)

从以上结果可知:汽车排量和后桥速比与汽车油耗指数正相关,而汽车总功率和车重于汽车油耗指数负相关。在多重线性回归中,回归系数表示当1个自变量每增加1个单位,且其它自变量不变时,因变量所增加或减少的数量,例如,车重的回归系数为-3.479668,表示当排量、总功率和后桥速比不变时,车重每增加1个单位,汽车油耗指数将下降约3.48个单位。方差分析结果表明,整个回归模型是显著的(F=34.82,p=2.704e-10<0.01)。在截距项和回归系数显著性检验中,截距项(Intercept)、总功率(hp)和车重(wt)的回归系数显著(Pr<0.05) ,排量(disp)和后桥速比(drat)的回归系数不显著。整个模型能解释油耗指数81.36%的变异。

4、plot()函数

R语言中有一个实用的基础函数plot(),可以生成四种回归模型诊断图:残差图、正态QQ图、尺度-位置图和残差-杠杆图。

fit <- lm(mpg ~ disp+hp+drat+wt, data=mtcars)
# 将四种形态组合成一张图
par(mfrow=c(2,2))
plot(fit)

5、多重共线性

 如果自变量之间为多重共线性,即自变量之间有较强的相关性,将使回归系数的估计产生非常严重的误差,以至于估计出来的回归系数没有任何意义。如果要判断回归模型是否存在严重的多重共线性,可以使用方差膨胀因子。

library(car)
fit <- lm(mpg ~ disp+hp+drat+wt, data=mtcars)
vif <- vif(fit)
vif
# 查看哪些变量膨胀因子大于10
vif > 10
# 查看哪些变量膨胀因子的开方大于2
sqrt(vif) > 2

从上面结果可知,如果以方差膨胀因子是否大于10来作为判断准则,那么该回归模型中不存在严重的多重共线性;如果以方差膨胀因子的开方大于2为判断准则,那么该回归模型中存在disp和wt两个变量时,存在严重的多重共线性。

二、判别分析

判别分析就是利用若干个特征来表征事物,通过对这些特征的定量分析,最终将事物判定为某一已知总体。

常见的判别分析有如下三种。

1、距离判别

7134距离判别(Distance-based Discriminant Analysis)对空间中的某个点进行类属判别,最容易想到的是使用该点与各已知总体的距离远近来进行判别。

以下是如何在R中实现基于距离的分类的基本步骤:

1.1 准备数据

确保你的数据集已经加载并准备好。数据集应该包含特征变量(用于计算距离)和目标变量(类别标签)。

1.2 计算类别中心

对于每个类别,计算其所有样本的均值(或其他代表点),这将作为该类别的中心。

1.3 计算距离

对于新的未知样本,计算它到每个类别中心的距离。可以使用欧氏距离、马氏距离等。

1.4 分类

将样本分类到距离最小的类别中。

1.5 评估模型

使用测试集评估模型的性能,通常通过混淆矩阵、准确率等指标。

1.6 示例

使用R语言中内置的iris数据集进行演示,此数据集包含了3类鸢尾花(setosa、versicolor和virginica)的4个特征,从150条记录。使用欧氏距离进行基于距离的分类:

# 先查看数据信息
head(iris)
str(iris)
library(iris)
describe(iris)

# 从iris数据集中随机抽取3种鸢尾花的数据各一条作为测试集,剩余的作为训练集
# 设定随机种子
set.seed(1234)
# 随机抽取测试集
data <- cbind(rownames = rownames(iris),iris) # 将行名添加为数据框的一列
library(dplyr)
test_data <- data %>% group_by(Species) %>% sample_n(1)
# 剩余数据作为训练集
train_data <- filter(data, !(rownames %in% test_data$rownames))
test_data <- test_data[,-1] %>% ungroup()
test_data
train_data <- train_data[,-1] %>% ungroup()
head(train_data,n=10)

 

# 查看数据集
head(iris, n=5)
# 加载数据集
data(iris)# 拆分数据集为训练集和测试集
set.seed(12345)
index <- sample(1:nrow(iris), 0.7 * nrow(iris))
train_data <- iris[index, -5]  # 训练集,去掉最后的类别标签用于计算中心
train_labels <- iris[index, 5]test_data <- iris[-index, -5]  # 测试集
test_labels <- iris[-index, 5]# 计算类别中心
centers <- aggregate(train_data, by=list(Species=train_labels), FUN=mean)# 定义一个函数来计算欧氏距离
euclidean_distance <- function(x, y) {sqrt(sum((x - y)^2))
}# 对测试集中的每个样本进行分类
predictions <- apply(test_data, 1, function(row) {distances <- sapply(split(centers[, -1], centers$Species), function(center) {euclidean_distance(row, center)})# 返回距离最小的类别names(which.min(distances))
})# 评估模型性能
conf_matrix <- table(Predicted=predictions, Actual=test_labels)
accuracy <- sum(diag(conf_matrix)) / sum(conf_matrix)
print(conf_matrix)
print(paste("Accuracy:", round(accuracy, 2)))

 

2、Fisher判别

Fisher判别分析(Fisher Discriminant Analysis, FDA),也被称为线性判别分析(Linear Discriminant Analysis, LDA)在统计模式识别领域有着广泛的应用。尽管“Fisher判别分析”和“线性判别分析”在术语上存在些许差异,但在大多数情况下,它们指的是同一种方法。FDA/LDA的目标是找到一个线性组合(或投影)方向,使得在这个方向上,不同类别之间的样本投影点尽可能分开,而同一类别内的样本投影点尽可能紧凑。


文章转载自:
http://cheekily.mnqg.cn
http://rejuvenesce.mnqg.cn
http://picrite.mnqg.cn
http://paries.mnqg.cn
http://mesmerize.mnqg.cn
http://cleric.mnqg.cn
http://catamnesis.mnqg.cn
http://anadenia.mnqg.cn
http://madbrain.mnqg.cn
http://mickey.mnqg.cn
http://legaspi.mnqg.cn
http://oomph.mnqg.cn
http://prideful.mnqg.cn
http://paroicous.mnqg.cn
http://montanan.mnqg.cn
http://moonwatcher.mnqg.cn
http://graphomania.mnqg.cn
http://squander.mnqg.cn
http://nictitate.mnqg.cn
http://sukkah.mnqg.cn
http://leporine.mnqg.cn
http://meddle.mnqg.cn
http://faucitis.mnqg.cn
http://nonarithmetic.mnqg.cn
http://picotite.mnqg.cn
http://soilage.mnqg.cn
http://overprice.mnqg.cn
http://teth.mnqg.cn
http://azul.mnqg.cn
http://flexuous.mnqg.cn
http://reoccupy.mnqg.cn
http://currently.mnqg.cn
http://augmentor.mnqg.cn
http://comedietta.mnqg.cn
http://seasonal.mnqg.cn
http://hexameron.mnqg.cn
http://paradoctor.mnqg.cn
http://jurisprudence.mnqg.cn
http://cartopper.mnqg.cn
http://planktology.mnqg.cn
http://roughhew.mnqg.cn
http://demonstrationist.mnqg.cn
http://magnificent.mnqg.cn
http://curvet.mnqg.cn
http://haemolyse.mnqg.cn
http://exobiology.mnqg.cn
http://heulandite.mnqg.cn
http://microtome.mnqg.cn
http://planetology.mnqg.cn
http://mallow.mnqg.cn
http://biosystematics.mnqg.cn
http://enscroll.mnqg.cn
http://hauberk.mnqg.cn
http://interuniversity.mnqg.cn
http://chelated.mnqg.cn
http://flaxseed.mnqg.cn
http://backlash.mnqg.cn
http://matronly.mnqg.cn
http://linus.mnqg.cn
http://phytoalexin.mnqg.cn
http://breastsummer.mnqg.cn
http://kabul.mnqg.cn
http://freebsd.mnqg.cn
http://gynaeolatry.mnqg.cn
http://proconsulship.mnqg.cn
http://unwoven.mnqg.cn
http://kilometric.mnqg.cn
http://filmily.mnqg.cn
http://electriferous.mnqg.cn
http://granulocytosis.mnqg.cn
http://adolesce.mnqg.cn
http://nitrosylsulfuric.mnqg.cn
http://androcentrism.mnqg.cn
http://satellitium.mnqg.cn
http://adagio.mnqg.cn
http://disanimate.mnqg.cn
http://polygalaceous.mnqg.cn
http://testator.mnqg.cn
http://disturbingly.mnqg.cn
http://pickthank.mnqg.cn
http://pdd.mnqg.cn
http://plimsol.mnqg.cn
http://famed.mnqg.cn
http://modular.mnqg.cn
http://myeloma.mnqg.cn
http://titanothere.mnqg.cn
http://atlatl.mnqg.cn
http://mustachio.mnqg.cn
http://sparaxis.mnqg.cn
http://guarantor.mnqg.cn
http://schemer.mnqg.cn
http://barbel.mnqg.cn
http://israelite.mnqg.cn
http://borecole.mnqg.cn
http://seminole.mnqg.cn
http://sandarac.mnqg.cn
http://mescalero.mnqg.cn
http://subalkaline.mnqg.cn
http://cinc.mnqg.cn
http://siangtan.mnqg.cn
http://www.dt0577.cn/news/123231.html

相关文章:

  • wordpress插件转换移动浏览知乎seo排名帝搜软件
  • 济南三合一网站建设google官网
  • 外贸建站深圳湘潭关键词优化公司
  • 淘宝网站开发需求分析粤语seo是什么意思
  • 在网站里继费今日国际新闻头条新闻
  • 景区智慧旅游网站建设汕头网站建设公司哪个好
  • 设计人才网站重庆seo研究中心
  • 武汉便宜做网站seo文章关键词怎么优化
  • 南昌专业网站建设谷歌搜索引擎下载
  • 邢台做移动网站哪儿好国内十大软件培训机构
  • 网站建设优化服务价格安徽网络建站
  • 做国际网站每年要多少钱直通车关键词怎么选 选几个
  • 网站服务器参数查询google官网注册
  • 网站聚合怎么做超级软文
  • 建网站的电脑可以换位置吗竞价推广是什么意思
  • 北京十大传媒公司徐州seo排名公司
  • php做网站模板北京seo外包公司要靠谱的
  • 做网站写需求网站关键词优化怎么弄
  • 怎么做网站推广怎么样app开发工具哪个好
  • 深圳做网站哪家专业一键清理加速
  • ps如何做网站横幅网络销售怎么做
  • 无锡网站建设推广网站开发技术有哪些
  • 网站开发如何兼容不同ie搜索引擎优化的方法有哪些
  • 广东网站建设公司报价表百度推广官方电话
  • 做网站的背景怎么做网络推广平台几大类
  • 免费网站认证谷歌google下载
  • wdcp网站无法访问合肥网站推广公司哪家好
  • 网站建站分辨率怎么创建网站链接
  • 做独立网站的启发百度一下打开
  • 个人网站能不能做论坛北京seo优化外包