Archive

Archive for the ‘R’ Category

rpy2 error when importing numpy array

December 14, 2011 Leave a comment

Get error when importing arrays from numpy to rpy2:

ValueError: Nothing can be done for the type <type ‘numpy.ndarray’> at the moment.
 Tried adding two additional import commands, and solved the problem:
import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()
Advertisements
Categories: Python, R

A note on randomForest in R

November 9, 2011 Leave a comment

Using the importance value to select features.

Link: http://www.statmethods.net/advstats/cart.html

RANDOM FORESTS

Random forests improve predictive accuracy by generating a large number of bootstrapped trees (based on random samples of variables), classifying a case using each tree in this new “forest”, and deciding a final predicted outcome by combining the results across all of the trees (an average in regression, a majority vote in classification). Breiman and Cutler’s random forest approach is implimented via therandomForest package.

Here is an example.

# Random Forest prediction of Kyphosis data
library(randomForest)
fit <- randomForest(Kyphosis ~ Age + Number + Start, data=kyphosis)
print(fit) # view results
importance(fit) # importance of each predictor

For more details see the comprehensive Random Forest website.

Categories: R