1. CART Tree

library(rpart)
library(rpart.plot)
CTree = rpart(Party ~ . -USER_ID, data = train, method = "class")
PredTest = predict(CTree, newdata = test, type = "class")  # result is bad

2. Cross validation

library(e1071)
library(caret)
set.seed(100)
numFolds = trainControl(method = "cv", number = 10)
cpGrid = expand.grid(.cp = seq (0.01,0.50,0.01))
tr = train(Party ~.- USER_ID,method = "rpart",data = train,trControl = numFolds, tuneGrid = cpGrid,na.action = na.pass)

Tip: the red part is to deal with missing NA values #cp = 0.04

3. CART Tree

CTree = rpart(Party ~ . -USER_ID, data = train, method = "class", cp = 0.04)
PredTest = predict(CTree, newdata = test, type = "class")

#after upload, the accuracy is 0.61207. it is my first time, the score is higher than the default logistic regression 0.57902

p.s. I also tried random forest

library(randomForest)
RFTree = randomForest(Party ~.- USER_ID,method = "rpart",data = train, ntree = 500, cp = 0.04, na.action = na.omit)

#The score is not good. 

2017/3/20 I am thinking i need to learn how to plot about the complex data structure. ggplot2. I think it's a good way for me.

[MACHINE LEARNING] Can we predict voting outcomes?的更多相关文章

  1. machine learning in action , part 1

    We should think in below four questions: the decription of machine learning key tasks in machine lea ...

  2. 7 Exciting Uses of Machine Learning in FinTech

    https://rubygarage.org/blog/machine-learning-in-fintech Machine learning (ML) has moved from the per ...

  3. Practical Machine Learning For The Uninitiated

    Practical Machine Learning For The Uninitiated Last fall when I took on ShippingEasy's machine learn ...

  4. Targeted Learning R Packages for Causal Inference and Machine Learning(转)

    Targeted learning methods build machine-learning-based estimators of parameters defined as features ...

  5. Introducing: Machine Learning in R(转)

    Machine learning is a branch in computer science that studies the design of algorithms that can lear ...

  6. 学习笔记之Machine Learning Crash Course | Google Developers

    Machine Learning Crash Course  |  Google Developers https://developers.google.com/machine-learning/c ...

  7. CheeseZH: Stanford University: Machine Learning Ex2:Logistic Regression

    1. Sigmoid Function In Logisttic Regression, the hypothesis is defined as: where function g is the s ...

  8. Machine Learning and Data Mining(机器学习与数据挖掘)

    Problems[show] Classification Clustering Regression Anomaly detection Association rules Reinforcemen ...

  9. [C5] Andrew Ng - Structuring Machine Learning Projects

    About this Course You will learn how to build a successful machine learning project. If you aspire t ...

随机推荐

  1. 流媒体压力测试rtmp&hls(含推流和拉流)

    http://blog.csdn.net/sinat_34194127/article/details/50816045 [root@localhost ~]# yum install git unz ...

  2. Scrapy学习篇(十二)之设置随机IP代理(IPProxy)

    当我们需要大量的爬取网站信息时,除了切换User-Agent之外,另外一个重要的方式就是设置IP代理,以防止我们的爬虫被拒绝,下面我们就来演示scrapy如何设置随机IPProxy. 设置随机IPPr ...

  3. CSV文件乱码展示(编码格式问题)

    最开始mac上打开CSV文件乱码,是这样的:CSV文件编码格式为UTF-8 解决办法一:将excel文件同样的转换编码格式为utf-8,具体操作如下: 去掉tab,勾选comma 最后,将文件另存为u ...

  4. SpringBoot,SpringCloud入门到精通最简单教程

    https://blog.csdn.net/ztx114/article/details/78091689

  5. leetcode621

    public class Solution { public int LeastInterval(char[] tasks, int n) { Dictionary<char, int> ...

  6. Mysql 和 SQLServer 使用SQL差异比较

    查询前100条数据 #mysql ; #sqlserver * from table_name ; 从数据库.表 定位表 #mysql写法:库名.表名 select password from Inf ...

  7. MM-实际应用中的难题

    SAP系统实际应用中的十大难题——塞依SAP培训 难题1:采购料维修 如果有物料坏了,需要退回给供应商处维修,此时一般不做退货.因为,第一,供应商不一定会乐意:第二,往来单据也无谓地增多:第三,最重要 ...

  8. 使用openpyxl复制整张sheet

    通过无能的baidu逛了一圈,发现有两三段能用的代码,不过参考之下,发现还有不足的: 不能拷贝有合并格式的sheet.没有拷贝cell的相关格式(填充.边框.对齐)等参数 所以通过bing继续发掘,最 ...

  9. HTML前期学习总结

    一.基本结构<!DOCTYPE html> //设置字符编码集格式<html> //<head> //网页头部 <title></title> ...

  10. python入门(七):字符串

    1.字符串类型: >>> s="早上好"               #str类型的字符串 >>> type(s) <class 'str ...