[Reading notes] machine learning: Practical Case Analysis (2)

Source: Internet
Author: User
Tags ggplot

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.