Calling regression from Python
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like to call logistic regression from Python. Seems like Python cannot handle the object returned by Matlab.
My code and error are below:
from __future__ import division
import matlab.engine
xVals = [[1,2,1],[1,3,1],[2,2,1]]
xVals = matlab.double(xVals)
yVals = matlab.double([1,0])
eng = matlab.engine.start_matlab()
[Mdl,FitInfo] = eng.fitclinear(eng.spconvert(xVals),eng.categorical(yVals), 'learner', 'logistic''PostFitBias',true, nargout=2)
Error message
[Mdl,FitInfo] = eng.fitclinear(eng.spconvert(xVals),eng.categorical(yVals), 'learner', 'logistic''PostFitBias',true, nargout=2)
File "/Library/Python/2.7/site-packages/matlab/engine/matlabengine.py", line 71, in __call__
_stderr, feval=True).result()
File "/Library/Python/2.7/site-packages/matlab/engine/futureresult.py", line 67, in result
return self.__future.result(timeout)
File "/Library/Python/2.7/site-packages/matlab/engine/fevalfuture.py", line 82, in result
self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
TypeError: unsupported data type returned from MATLAB
0 Kommentare
Antworten (1)
Rajani Mishra
am 27 Mai 2020
When calling a MATLAB function using MATLAB engine, by default the engine returns a single output argument. To have multiple output arguements we use nargout to specify the number of output arguements, which is 2 in this case. So using
t = eng.fitclinear(eng.spconvert(xVals),eng.categorical(yVals), 'learner', 'logistic''PostFitBias',true, nargout=2)
where t will hold both output arguements. As specified in the example on this page (Second Example):
0 Kommentare
Siehe auch
Kategorien
Mehr zu Call MATLAB from Python finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!