Rで何かをしたり、読書をするブログ

政府統計の総合窓口のデータや、OECDやUCIやのデータを使って、Rの練習をしています。ときどき、読書記録も載せています。

World Bank Income share held by lowest 20% data analysis 6 - Tree-Based Regression in R.

Generated by Bing Image Creator: Earth and Winds and Fire Landscape, photo

www.crosshyou.info

This post is following of the above post. In the previous post, I did linear regression with both traditional way and modern way.

In this post I will do tree-based regression.

First, I load rpart package.

Then, let's fit tree model

Next, I use plotcp() function to check if we need prune the tree or not.

It shows cp = 0.11 is the best cp. So I prune the tree with cp = 0.11.

Let's see the result.

I use rpart.plot library to visualize the result.

The result is quite simple, if Y2006 is greater than or equalt to 7.7, Chg_Net would be -0.15, otherwise, Chg_Net is 0.78.

That's it. Thank you!

Next post is

www.crosshyou.info

 

To read from the first post,

www.crosshyou.info