MLR: Function "predict.WrappedModel" not found - mlr

I am using R 3.6.1, RStudio 1.2.5019 and mlr 2.15.0. Mlr ist installed and loaded. Only mlr and the packages mlr is built on are loaded.
Now, I have trained a model using train and would like to test it on new data.
Therefore, I want to use the predict.WrappedModel function from mlr.
If I call
?predict.WrappedModel I get all the information in the help window.
However, if I want to run predict.WrappedModel R throws an error indicating that the function cannot be found:
my_test = predict.WrappedModel(object = my_model, task = my_task)
konnte Funktion "predict.WrappedModel" nicht finden
Even when specifying mlr as the package to look in for the function:
my_test = mlr::predict.WrappedModel(object = my_model, task = my_task)
Fehler: 'predict.WrappedModel' ist kein von 'namespace:mlr' exportiertes Objekt
I also tried using ?predict , but here I also got an error:
my_test = mlr::predict(object = my_model, task = my_task)
Fehler: 'predict' ist kein von 'namespace:mlr' exportiertes Objekt
I've already spent a lot of time trying to fix this issue and read all the related questions I had found here and on the mlr forum on github, but could not find a solution.
What am I missing here?
Thanks a lot in advance :)

You neither need predict.WrappedModel nor mlr::predict. Both are internal functions using the generic S3 approach in R to operate based on the class of the supplied R object.
So in this case, as long as you pass a object derived from a mlr::train() call everything will just work.
Speaking with code:
library("mlr")
my_model = train(learner, task)
predict(my_model, task)

Related

Access Error Language - Error '-2147319779 (8002801d)' in the execution time

I have a function that checks whether the excel configuration is in English or Spanish to set the name of the spreadsheet.
Public Function VersionExcel(ByVal appxls As excel.Application) As String
Dim Hoja1 As String
'Si aplicacion en ingles
If (appxls.LanguageSettings.LanguageID(1) = 1033) Then
Hoja1 = "Sheet1"
Else
Hoja1 = "Hoja1"
End If
VersionExcel = Hoja1
End Function
It has been working for almost 10 years, but lately I have been getting this error when executing that code:
[Code Stop] https://imgur.com/ZlQXv0o
[Error message] https://imgur.com/BUEYAGA
"Error '-2147319779 (8002801d)' in the execution time.
Method 'LanguageSettings' error for the object '_Application'"
In certain PCs works and in others don´t. What can be wrong with the configuration of the Excel to get this error?
I have already checked that the references are the same. But I am kinda getting crazy with this issue.
This may be a Late / Early Binding issue.
If your users have different versions of Access and the version this is developed/compiled in is a later version then early binding the object reference won't work.
Review https://support.microsoft.com/en-gb/help/245115/using-early-binding-and-late-binding-in-automation for more assistance

Error in mcp2matrix(model, linfct = linfct)

I don't understand why it is not working for the post hoc test. What did I do wrong?
modmisto<-lme(Cobertura~Tratamento, random=~1|Parcela, data=Cover_BraquiT3)
summary(modmisto)
tukey<-glht(modmisto, mcp(Tratamento="Tukey"))
Error in mcp2matrix(model, linfct = linfct) :
Variable(s) ‘Tratamento’ of class ‘character’ is/are not contained as a factor in ‘model’.
Any help with this will be very appreciated!
Tratatmento does not seem to be a factor variable, try put this before:
Cover_BraquiT3$Tratamento = as.factor(Cover_BraquiT3$Tratamento)
A variable in my data.frame was of type character.
The glht function did not recognize it as a factor in the model generated by the glm function.
I Tried:
variable = as.factor (variable)
I only managed using:
library (tibble)
data <-as_tibble (data)%>%
mutate (variable = factor (variable))

boto.sqs: read and write SQS messages

I would like to read messages from one que and write them to another que. But, the message class is custom format and I am not sure how to write a message class and import it.
That is, the structure follows as:
import boto.sqs
#read messages from one que
conn = boto.sqs.connect_to_region("regionName")
q=conn.get_queue('queueName')
res=q.get_messages()
m = res[0].get_body() #This is the message I read
#Now, I want to write the message into another que
r = conn.get_queue('DifferentqueueName')
r.write(m)
Here, the code breaks and I get the following error messages:
224 new_msg = self.connection.send_message(self,
--> 225 message.get_body_encoded(), delay_seconds=delay_seconds,
226 message_attributes=message.message_attributes)
227 message.id = new_msg.id
AttributeError: 'unicode' object has no attribute 'get_body_encoded'
How can define a custom message class and use it to write to another que? Or, if I could just inherit the class when reading messages and use it for writing, that would be even easier. Can I do any of these?
Thank you.
The reason you are getting the error is because you are attempting to write a raw string to the queue rather than a Message object. Try this, instead:
import boto.sqs
#read messages from one que
conn = boto.sqs.connect_to_region("regionName")
q1 = conn.get_queue('queueName')
q2 = conn.get_queue('DifferentqueueName')
messages = q1.get_messages()
for message in messages:
msg_body = message.get_body() #This is the message I read
# Now, I want to write the message into another queue
new_msg = q2.new_message(msg_body)
q2.write(new_msg)
garnaat's code was problemetic for me (I'm reading the queue with the Java SDK maybe that is the reason) so I used a slight veriation on it:
import boto.sqs
from boto.sqs.message import RawMessage
conn = boto.sqs.connect_to_region("avilability_zone")
q1 = conn.get_queue('original_queue')
q2 = conn.get_queue('new_queue')
for i in range(1,400):
messages = q1.get_messages(10)
for message in messages:
msg_body = message.get_body()
new_msg = RawMessage()
new_msg.set_body(msg_body)
q2.write(new_msg)
q1.delete_message(message)
print("{}/400".format(i))

Perl variable set from query string not available in subroutine (available in some subroutines!)

Perl has beaten me down good today and I have a question. I'm accessing a perl script via a link from another perl script. agent.pl?agentid=40
In the agent.pl script I'm using the displaying the query string without issues in two different ways:
my $thatagent = $q->param('agentid');
$form{agentid}
I set the lexical variable at the beginning of my script of outside of all subroutine. I then use $thatagent to display the agent id number in the "default" subroutine which displays HTML when the script runs. I don't have any issues here.
$dbh->{AutoCommit} = 0;
my $q = CGI->new;
my $thatagent = $q->param('agentid');
my %form = $q->Vars;
if (! $q->param("savebtn")) {
&ViewAgent();
exit;
}
&UpdateAgent();
I call two subroutines from the viewagent subroutine and use $form{agentid} in select statements also without issue.
my $sth = $dbh->prepare("select a.name, a.paidcommission, a.paidreferral, paddy.address1, paddy.address2, paddy.city, paddy.state, paddy.zipcode, maddy.address1, maddy.address2, maddy.city, maddy.state, maddy.zipcode, bc.name, bc.phonenumber, bc.phoneext, bc.phonenumber2, bc.phoneext2, bc.fax, bc.email, sc.name, sc.phonenumber, sc.phoneext, sc.phonenumber2, sc.phoneext2, sc.fax, sc.email from agent a inner join entity e on entityid = agentid inner join address paddy on paddy.addressid = physicaladdressid inner join address maddy on maddy.addressid = mailingaddressid inner join contact bc on bc.contactid = billingcontactid inner join contact sc on sc.contactid = salescontactid where a.agentid = $form{agentid};") or die "prepare statement failed: $DBI::errstr\n";
and
my $sth = $dbh->prepare("select agentid, note, createdt, createuser from agentnote where agentid = $form{agentid};") or die "prepare statement failed: $DBI::errstr\n";
Then comes the problem, I call another subroutine (&updateagent listed above) globally and attempt to use $thatagent but it fails. If I hard code a number, it works just fine.
sub UpdateAgent {
my $sth = $dbh->prepare("UPDATE agent SET name=?, paidcommission=?, paidreferral=? WHERE agentid=?;") or die "prepare statement failed: $DBI::errstr\n";
$sth->execute($form{'name'}, $form{'paidcommission'}, $form{'paidreferral'}, $thatagent) or die "prepare statement failed: $DBI::errstr\n";
$sth->finish;
}
I feel I must have some sort of disconnect with my subroutine "seeing" the rest of my script but am unsure. Please help!
Thanks in advance :)
I'm guessing you are running this script under some kind of system such as mod_perl, where the .pl file gets compiled into a subroutine that is called as needed. The actual code ends up looking like this:
sub invoke_agent_pl {
...
my $thatagent = ...;
...
sub updateagent {
...
# do something with $thatagent
...
}
}
What happens here is that the $thatagent variable used by updateagent isn't always the same as the $thatagent variable set by the automatically created wrapper invoke_agent_pl.
The easiest fix is to say our $thatagent, not my. Better is to not use what are essentially global variables in your script.
OK, so I added
my #thatagent = split(/=/,$ENV{'QUERY_STRING'});
my $thatagent = $thatagent[1];
and it kept the variable throughout the script.
I don't know a whole lot about Perl, but man that seems weird. Like I said, in the initial subroutine displaying the HTML (and the two subroutines called from the HTML subroutine) I was able to use
$form{agentid}
from where I read my cgi parameters into a hash without issue.

Using functions on callbacks of a GUI

I'm using GUIDE to create an interface where a function [x,y]=function(a,b,c,d) will be executed when the button is clicked. Im having problems to get this to work. GUIDE creates an autogenerated function with the syntax varargout = LineasA(varargin).
I'm calling the GUI using this syntax [x,y]=LineasA(a,b,c,d).
Errors I get are:
Error in ==> LineasA>LineasA_OutputFcn at 73
varargout{1} = handles.output;
??? Error using ==> feval
Output argument "varargout{2}" (and maybe others) not assigned during call to
"C:\Users\ZeTa\Documents\MATLAB\ImagenB\LineasA.m>LineasA_OutputFcn".
Error in ==> gui_mainfcn at 263
[varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [],
gui_Handles);
Error in ==> LineasA at 40
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
Error in ==> ImagenB at 17
[MatrizB,Cuenta]=LineasA(Cuenta,waveformObj,channelObj,MatrizB);
You have to be clear where you are getting the inputs to this function, and where you want the outputs to go. It is proper coding to store the inputs and outputs in the handles struct that is passed into the callback. Also, the proper callback structure is:
LineasA(hObject, eventdata, handles)
However, if you insist on calling and storing from the base workspace, you can do as follows:
LineasA(hObject, eventdata, handles)
% grab values from base workspace
Cuenta = evalin('base', 'Cuenta');
waveformObj = evalin('base', 'waveformObj');
channelObj = evalin('base', 'channelObj');
MatrizB = evalin('base', 'MatrizB');
% the rest of your code
% assign outputs
assignin('base', 'MatrizB', matrizB);
assignin('base', 'Cuenta', Cuenta);
end
However I recommend getting those values in the handles structure and not to use evalin and assignin, they are usually bad coding techniques.