I am trying to figure how to get the linear model at each leaf of a tree generated by M5P method in RWeka library in R as an output to text file so that I can write a separate look up calculator program (say in Excel for non-R Users).
I am using
library (RWeka)
model = M5P (response ~ predictorA+predictorB, data=train).
I can get the tree output as model$classifier in a matrix. This works great thanks to This post
If I give the command:
model
R prints the model$classifier (the tree structure), followed by the LM at each leaf, I want to extract the coefficients of LM at each leaf.
Using the following code: I am able to get the LM coefficients out of R.
library(rJava)
ModelTree=as.matrix(scan(text=.jcall(model$classifier, "S","toString") ,sep="\n", what="") )[-c(1:2, 6), ,drop=FALSE]
Related
I would like to run a mixed model in R specifycing the object for the structure of a random effect.
My model is this:
model1=lme(methane~fixedfactor1,
random=(~1|factory),
data=df,method="REML")
I have then an object named "factory_relationship" that I would like to use to model the structure of the random effect "factory".
If it can help, I did it in SAS by using the following:
proc mixed data=methane_data NOINFO;
class fixedfactor1;
model methane= fixedfactor1;
random factory/type=lin(1) LDATA=factory_relationship;
run;
However, I could not find any solutions in R.
Could you please help me?
Best
I tried to read the PDF guidelines for both "nlme" and "lme4" R packages, but I could not find any hint.
Hi I am a newbie in Depp learning fields.
I ran a neural network model (regression) with 2 hidden layers in R (neuralnet Package). then I used the the compute function to get the predicted probabilities.Now I want to regenerate predicted output using the equation used in the neural net. for example, following are weights received from the model object
Intercept.to.1layhid1 4.55725020215
Var1.to.1layhid1 -13.61221477737
VAr2.to.1layhid1 0.30686384857
var1.to.1layhid2 0.23527690062
var2.to.1layhid2 0..67345678
1layhid.1.to.target 1.95414397785
1layhid.2.to.target 3.68009136857
Can any one help me derive a equation with the above weights so that I can replicate the output
Thanks
In order to get the output for new data, you can always use predict function using the fitted model, which is the returned object from neuralnet function.
For instance, if your model is the following:
neuralFit = neuralnet(trainData)
Then you reproduce the output with the following:
predict(neuralFit,newdata)
Otherwise, you'll need to compute the result manually. But you need to understand your network architecture first.
I can't figure out how to specify the model type in package eHOF (I want to plot a model other than the one chosen by the program). I create a HOF object:
sg.hof <- HOF(SG_Pres, logdtw, M=1, family=binomial, bootstrap=NULL)
This fits the seven hierarchical regression models, and works fine, but let's say the program chooses model VI as being the best, but I want to use model III instead, how do I plot model III? I thought something like this would work, but it doesn't:
plot(sg.hof, para=TRUE, model=3)
Can anyone help me?
plot(sg.hof, para=TRUE, model='III')
While trying to export an R classifier to PMML, using the pmml package, I noticed that the class distribution for a node in the tree is not exported.
PMML supports this with the ScoreDistribution element: http://www.dmg.org/v1-1/treemodel.html
Is there anyway to have this information in the PMML? I want to read the PMML with another tool that depends on this information.
I'm doing something like:
library(randomForest)
library(pmml)
iris.rf <- randomForest(Species ~ ., data=iris, importance=TRUE,proximity=TRUE)
pmml(iris.rf)
Can you provide some more information..such as, which function you are trying to use.
For example, if you are using the randomForest package, I believe it doesn't provide information about the score distribution; so neither can the PMML representation. However, if you are using the default values, the parameter 'nodesize' for classification ceses, for example, equals 1 and that means the terminal node will have a ScoreDistribution such as:
ScoreDistribution value=predictedValue probability="1.0"/>
ScoreDistribution value=AnyOtherTargetCategoty probability="0.0"/>
If you are using the rpart tree model, the pmml function does output the score distribution information. Perhaps you can give us the exact commands you used?
I am using the tree library in R, but when I fit the data into the tree command, sometimes I get a regression tree and sometimes a classification tree. What is this about? Thanks!
From the help page (?tree)
The left-hand-side (response) should be either a numerical vector when
a regression tree will be fitted or a factor, when a classification
tree is produced.