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. day32基于tcp协议的远程执行命令

    客户端 from socket import *import structimport json client = socket(AF_INET, SOCK_STREAM)client.connect ...

  2. WPF 流加载

    /// <summary> /// datatable分页 /// </summary> /// <param name="dt">源datat ...

  3. (转)适用微信小程序的table表格(带隔行变色)

    原文地址 table.wxml <view class="table"> <view class="tr bg-w"> <view ...

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

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

  5. volatile适用场景之二

    1.volatile最适用一个线程写,多个线程读的场合. 如果有多个线程并发写操作,仍然需要使用锁或者线程安全的容器或者原子变量来代替.(摘自Netty权威指南) 疑问:如果只是赋值的原子操作,是否可 ...

  6. orcal - 单行函数

    虚拟表:dual 转大写 select UPPER('hellow') from dual; 转小写 select lower(ename) from emp; cmd 输入数据 select * f ...

  7. JSX

    有一个 Babel 插件,用于在 Vue 中使用 JSX 语法,它可以让我们回到更接近于模板的语法上.JSX语法返回一个vnode对象 import AnchoredHeading from './A ...

  8. leetcode394

    class Solution { public: string decodeString(string s) { stack<string> chars; stack<int> ...

  9. Thinkphp语句拼接

    例如查询Stu表中年龄大于18,或者身高低于180cm的男性(1为男性),(例子不太好标题有可能不符,望见谅) $where['age'] = array("gt",18); $w ...

  10. 让openvpn自启动的命令笔记(windows)

    "C:\Program Files\OpenVPN\bin\openvpn.exe" --client-config-dir "C:\Program Files\Open ...