The 2nd Chapter data analysis
#machine learing for Heckers
#chapter 2
Library (GGPLOT2) heights.weights <-read.csv ("Ml_for_hackers/02-exploration/data/01_heights_weights_ Genders.csv ", header = TRUE, Sep =", ")
#不同区间宽度的直方图
Ggplot (Heights.weights, aes (x = height)) + geom_histogram (binwidth = 1) ggplot (Heights.weights, aes (x = height)) + geom_his Togram (binwidth = 5) ggplot (Heights.weights, aes (x = Height)) + geom_histogram (binwidth = 0.001)
#密度曲线图
Ggplot (Heights.weights, aes (x = Height)) + geom_density ()
#峰值处平坦, consider the structure of the image is missing, according to the gender plot density graph
Ggplot (Heights.weights, aes (x = Height, fill = Gender)) + geom_density () Ggplot (Heights.weights, aes (x = Weight, fill = Gen Der) + geom_density () Ggplot (Heights.weights, aes (x = Weight, fill = Gender)) + geom_density () + Facet_grid (Gender ~.)
#正态分布: Bell-shaped narrow tail distribution, single-peak symmetry
#柯西分布: Bell-shaped heavy-tailed distribution, single-peak symmetry
Set.seed (1) normal.values <-rnorm (0, 1) cauchy.values <-rcauchy (+, 0, 1) ggplot (data.frame (X = normal.values ), AES (x = x)) + geom_density () Ggplot (data.frame (x = cauchy.values), AES (x = x)) + geom_density ()
#gamma分布
#gamma分布只有正值
Gamma.values <-Rgamma (100000, 1, 0.001) Ggplot (data.frame (x = gamma.values), AES (x = x)) + geom_density ()
#从身高体重预测性别 (classifier)
#书中代码画图命令有 "Stat_abline" completes the Add line operation, while the "stat" family function in Package:ggplot2 (version 2.1.0) has no "abline" and can only be done with the "Geom" family
Heights.weights <-transform (heights.weights, Male = ifelse (Gender = = ' Male ', 1, 0)) Logit.model <-GLM (Male ~ Weight + Height, data = heights.weights, family = binomial (link = ' logit ')) Ggplot (Heights.weights, aes (x = Height, y = weigh T, color = Gender)) + geom_point () + geom_abline (Intercept =-COEF (Logit.model) [1]/coef (Logit.model) [2], slope =-coef (Logit.model) [3]/coef (Logit.model) [2], color = ' black ')
[Reading notes] machine learning: Practical Case Analysis (2)