Errors - bootstrap GLM model - glmmBoot package - glm

I'm trying to run a bootstrap resampling on a GLM model, but I keep running into errors and I can't find any solution online.
The first problem in which I ran into is "variable lenght differs" when i try to use a normalized variable (sub.size_z) and a continuous variable trasformed into factor (hours). I checked my dataset and there are no NAs anywhere, so i don't know how to tackle the problem.
The second error is "Error: Naming mismatch from base to list of coefs", which happens when i try to run the bootstrap using a GLM without having trasformed the variables that i previously mentioned.
Can anyone point me towards a solution? Thanks a lot!
Here's the code I used!
data <-read.delim2("C:/Users/BRIZ_/Desktop/analisi scratching/Hypothesis 3/Hypothesis 3/database.txt")
library(car)
library(lme4)
library(MASS)
library(dplyr)
library(blmeco)
library(MuMIn)
library(lmerTest)
library(AER)
library(DHARMa)
sub.size_z<-scale(sub.size, center=TRUE,scale=TRUE)
hours<- as.factor(hour)
modelboot<-glmmTMB(sc.count~ offset(log(DURATION)) + hours + general.activity + sub.size_z + approach5+ id,data=data, family=genpois(link = "log"))
summary(modelboot)
bootstrap_model(modelboot,base_data=data,resamples =100)

Related

I'm trying to plot the confusion matrix for the predictions on my test set using my neural network model, but this error keeps on popping out

I'm trying to plot the confusion matrix for the predictions on my test set using my neural network model, but this error keeps on popping out. Can you please help me out. I tried to clicked the search on stackoverflow, but I didn't get a definitive answer. Can someone please help me out to resolve this error and pinpoint what error I have made? Also, if possible, what suggestions can you give? Thank you so much. Here is the picture of my code and this is my actual work
This is the code:
cm_plot_labels=['adobong baboy', 'arroz caldo','bagnet','balut','bicol express','biko' ,'binignit','bulalo','caldereta','camaro rebusado','champorado',
'chicharon','chicken inasal','cooked white rice','fish kinilaw','halo halo','liempo','maja blanca','pancit habhab', 'pandesal', 'pastillas de leche','pichi pichi',
'puto bumbong','puto rice cake','rellenong alimango','sinugno','sisig','suman','tapa','tinola','tuna panga','turon','ube halaya' ]
plot_confusion_matrix(cm=cm, classes=cm_plot_labels, title='Confusion Matrix')
As the error states, 'plt.cm.Blues' is not a valid value for the cmap argument of the plt.imshow function. The error suggests possible valid values that can be passed as the cmap value.
So, to solve your error you should be able to just set the default value of cmap in the plot_confusion_matrix function parameters to the string value 'Blues' instead of 'plt.cm.Blues'.
Here is the documentation for the plt.imshow function which you are using. Here it gives details of what the parameters are (including cmap) and what valid values can be passed to them.
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html

H2O POJO causing javac java.lang.IllegalArgumentException

I have a distributed random forest POJO model using the default model setting except for:
ntrees = 150
max_depth = 50
min_rows = 5
Here are the full settings:
buildModel 'drf', {"model_id":"drf-335270ee-8970-4855-b521-c4fb4ca184f5","training_frame":"frame_0.750","validation_frame":"frame_0.250","nfolds":0,"response_column":"DENIAL","ignored_columns":["tx_match_date"],"ignore_const_cols":true,"ntrees":"150","max_depth":"50","min_rows":"5","nbins":20,"seed":-1,"mtries":-1,"sample_rate":0.6320000290870667,"score_each_iteration":true,"score_tree_interval":0,"balance_classes":false,"nbins_top_level":1024,"nbins_cats":1024,"r2_stopping":1.7976931348623157e+308,"stopping_rounds":0,"stopping_metric":"AUTO","stopping_tolerance":0.001,"max_runtime_secs":0,"checkpoint":"","col_sample_rate_per_tree":1,"min_split_improvement":0.00001,"histogram_type":"AUTO","categorical_encoding":"AUTO","build_tree_one_node":false,"sample_rate_per_class":[],"binomial_double_trees":true,"col_sample_rate_change_per_level":1,"calibrate_model":false}
When I try to compile the pojo with:
$javac -cp "h2o-genmodel.jar" -J-Xmx2g -J-XX:MaxPermSize=128m drf_335270ee_8970_4855_b521_c4fb4ca184f5.java
I get the following error.
An exception has occurred in the compiler (1.8.0_131). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.IllegalArgumentException
at java.nio.ByteBuffer.allocate(ByteBuffer.java:334)
at com.sun.tools.javac.util.BaseFileManager$ByteBufferCache.get(BaseFileManager.java:325)
at com.sun.tools.javac.util.BaseFileManager.makeByteBuffer(BaseFileManager.java:294)
at com.sun.tools.javac.file.RegularFileObject.getCharContent(RegularFileObject.java:114)
at com.sun.tools.javac.file.RegularFileObject.getCharContent(RegularFileObject.java:53)
at com.sun.tools.javac.main.JavaCompiler.readSource(JavaCompiler.java:602)
at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:665)
at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
at com.sun.tools.javac.main.Main.compile(Main.java:381)
at com.sun.tools.javac.main.Main.compile(Main.java:370)
at com.sun.tools.javac.main.Main.compile(Main.java:361)
at com.sun.tools.javac.Main.compile(Main.java:56)
at com.sun.tools.javac.Main.main(Main.java:42)
I don't get this error when replacing the DRF model with a deep learning pojo that I have also downloaded from h2o's Flow UI, so I'm thinking it is likely related to the drf_335270ee_8970_4855_b521_c4fb4ca184f5.java file (note that the POJO was too big to preview in H2O's Flow UI). What could be going on here?
Thanks
Instead of trying to compile an H2O random forest POJO, you can download and use a MOJO instead in almost exactly the same way without needing the compile step.
See:
http://docs.h2o.ai/h2o/latest-stable/h2o-genmodel/javadoc/index.html

Error using Caffe: "This tool requires OpenCV; compile with USE_OPENCV."

I want to use Caffe's tool, compute_image_mean to compute the mean image, but the command line tells me that:
This tool requires OpenCV; compile with USE_OPENCV.
I've searched the Internet, and one guy said:
Well, this message suggests that you have compiled caffe without
OpenCV, i.e; with USE_OPENCV set to 0 in your Makefile.config.
Recompile with that settings commented out (as is the default) and try
again. And of course you need to have OpenCV installed for this to
work.
But I have already set USE_OPENCV := 0 when I compiled my Caffe.
Could someone help me to solve this problem?
I think you have misread the statement you found, it says you are compiling without OpenCV, which means WITH_OPENCV := 0 , to compile Caffe with OpenCV you have to set WITH_OPENCV := 1 , or just comment it out.
I met the same error information when I used caffe to do my work. I solved this problem by modifying something in the "Makefile.config" file.
The same as the lastest answer, I commented this line "USE_OPENCV := 0" with "#", so after compiling I can use OpenCV's function. I can use this way to deal with it, but you said that when you did this action and got another error. I think you didn't install your OpenCV correctly. Maybe it's your version problem or environment variable error. You can try to install OpneCV again.
I met the same error when I tried to make lmdb.
At first I uncomment "USE_OPENCV:=0" in the Makefile.config and recompile for many times, but it does not help.
So I try to comment "USE_OPENCV:=0" with # and recompile the caffe, it success.

Cannot get SURF example in EMGU.CV to work?

I am trying to detect a pattern shown in two images. Hence I have been trying to use the SURF algorithim found in emgu.CV, but the "SURFFeature" example that is given gives me the following error:
An unhandled exception of type 'Emgu.CV.Util.CvException' occurred in Emgu.CV.dll
Additional information: OpenCV: norm == NORM_L1 || norm == NORM_L2 || norm == NORM_HAMMING
Any ideas how to fix this?
When I try the "Hello World" example and the face detection example, both seem to work fine.
Thanks for any advice!
Fouad.
PS: Emgu.CV can be downloaded from here: http://www.emgu.com/wiki/index.php/Main_Page
Apparently the build was messed up.
http://www.emgu.com/bugs/show_bug.cgi?format=multiple&id=74
Aha, found it. The error here is in Emgu.Cv.Gpu/GpuBruteForceMatcher.cs lines 22 and 27.
Line 22 currently reads:
L2Dist,
It should read: L2Dist = 4,
Line 27 currently reads: HammingDist
It should read: HammingDist = 6
Rebuild the Emgu.CV.Gpu dll with those changes and it works.

Can't figure out error while running CVB0Driver in Mahout

I've been trying for the last few hours to get CVB0Driver working and after much trial and error I've come to the following error which I can't figure out. (Using mahout-integration 0.7)
java.lang.Error: Unresolved compilation problem:
at org.apache.mahout.math.function.Functions.mult(Functions.java:770)
at org.apache.mahout.clustering.lda.cvb.TopicModel.<init>(TopicModel.java:139)
at org.apache.mahout.clustering.lda.cvb.TopicModel.<init>(TopicModel.java:113)
at org.apache.mahout.clustering.lda.cvb.TopicModel.<init>(TopicModel.java:108)
at org.apache.mahout.clustering.lda.cvb.TopicModel.<init>(TopicModel.java:92)
at org.apache.mahout.clustering.lda.cvb.CachingCVB0Mapper.setup(CachingCVB0Mapper.java:103)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:142)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
Here's the code I'm using, since I have yet to get it working I'm not sure if I'm on the right path, so feel free to comment if you see a mistake I'm making.
String [] args = {"-c","UTF-8","-i",input,"-o",output};
//create the seq file from the directory of text documents
ToolRunner.run(new SequenceFilesFromDirectory(),args);
//tokenize the documents
DocumentProcessor.tokenizeDocuments(new Path(inputDir), analyzer.getClass().asSubclass(Analyzer.class), tokenizedPath, conf);
//create tf vectors
DictionaryVectorizer.createTermFrequencyVectors(tokenizedPath,new Path(outputDir), DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER, conf, minSupport, maxNGramSize, minLLRValue, -1.0f, true, reduceTasks, chunkSize, sequentialAccessOutput, true);
//calculate the document frequencies
Pair<Long[], List<Path>> dfData = TFIDFConverter.calculateDF( new Path(outputDir, DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER), new Path(outputDir), conf, chunkSize);
//create tfidf vectors
TFIDFConverter.processTfIdf( new Path(outputDir , DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER), new Path(outputDir), conf, dfData, minDf, maxDFPercent, norm, true, sequentialAccessOutput, true, reduceTasks);
args = new String[]{"-i","tfidf-vectors/part-r-00000","-o","cvb"};
//create the matrix for cvb
RowIdJob.main(args);
CVB0Driver.run(conf, new Path("cvb/matrix"), mto, numTopics, numTerms, alpha, eta, maxIterations, iterationBlockSize, convergenceDelta, dictionaryPath, dto, msto, randomSeed, testFraction, numTrainThreads, numUpdateThreads, maxItersPerDoc, numReduceTasks, backfillPerplexity);
Any help would be much appreciated.
Okay, seems this was some conflict between maven/eclipse projects.
I had recently imported the mahout-integration 0.7 source into eclipse and somehow badly built it, there was issues with mahout-math and my other project maybe started referencing the badly built jar, I'm not too familiar with maven so I don't know if that was the case or eclipse just went a bit crazy.
After deleting this project from eclipse, everything started to run fine.
This question helped resolve this one - java-unresolved-compilation-problem

Resources