zoukankan      html  css  js  c++  java
  • [读书笔记]机器学习:实用案例解析(2)

    第2章  数据分析

    #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_histogram(binwidth = 5)
    ggplot(heights.weights, aes(x = Height)) + geom_histogram(binwidth = 0.001)
    

      

          

    #密度曲线图

    ggplot(heights.weights, aes(x = Height)) + geom_density()
    

      

    #峰值处平坦,考虑图像有结构缺失,根据性别分别绘制密度曲线图

    ggplot(heights.weights, aes(x = Height, fill = Gender)) + geom_density()
    ggplot(heights.weights, aes(x = Weight, fill = Gender)) + geom_density()
    ggplot(heights.weights, aes(x = Weight, fill = Gender)) + geom_density() + facet_grid(Gender ~ .)
    

      

               

    #正态分布:钟形的窄尾分布,单峰对称
    #柯西分布:钟形的重尾分布,单峰对称

    set.seed(1)
    normal.values <- rnorm(250, 0, 1)
    cauchy.values <- rcauchy(250, 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()
    

      

    #从身高体重预测性别(分类器)

    #书中代码画图命令有"stat_abline"完成添加直线操作,而package: ggplot2(version 2.1.0)中"stat"族函数已经没有"abline",只能用"geom"族完成

    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 = Weight, 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')
    

      

  • 相关阅读:
    使用私有api实现自己的iphone桌面,并根据app的使用次数对app排序
    坐标系的属性
    带坐标轴的几何画板
    空间几何体的直观图matlab
    设置npm的registry
    (原创)机器学习之numpy库中常用的函数介绍(一)
    (原创)交叉编译 tesseract
    (原创)计算机视觉之数学原理-基础篇
    (原创)nRF51 DFU 初始化包介绍及生成工具
    (原创)使用nRF51822/nRF51422创建一个简单的BLE应用 ---入门实例手册(中文)之五
  • 原文地址:https://www.cnblogs.com/gyjerry/p/5562095.html
Copyright © 2011-2022 走看看