Got this error ='MultinomialNB' object has no attribute 'coef_' - coefficients

'MultinomialNB' object has no attribute 'coef_'
i tried this=
#adj = list(zip(model.coef_[0], cv.get_feature_names()))
but got the error saying that =multinomialNB object has no attribute coef_

.coef_ for multinomialNB has been deprecated since version 0.24 and it has been removed in 1.1 (renaming of 0.26).
By reading https://github.com/scikit-learn/scikit-learn/issues/7233 you get that coef_ is just taken from the .feature_log_prob_ method. So basically if you use:
list(zip(model.feature_log_prob_[0], cv.get_feature_names()))
you should get the same result.
If you are wondering why .coef_ has been deprecated, you can find your answer in this issue: https://github.com/scikit-learn/scikit-learn/issues/2237 i.e. "The coef_ and intercept_ on MultinomialNB don't behave like other linear models because they contain probabilities even in the binary case. They should contain log-odds ratios."

Related

The log-likelihood function of ARMA model after the deprecation of the statsmodels.tsa.arima_model.ARMA

I am following a tutorial building an AR model using ARMA model from statsmodels.tsa.arima_model, I got an error that it has been deprecated, and it is replaced by ARIMA from statsmodels.tsa.arima.model. I am trying to write a function that calculate a test statistic of the log-likelihood ratio test, which requires the use of the llf attribute of an initialized ARMA model. I do not know what is the counterpart of llf attribute in ARIMA model?
I tried statsmodels.tsa.arima.model.ARIMA.fit().loglike() but I did not know what kind of parameter it should get?
ar_2_model = ARIMA(data, order=(2,0,0) ).fit()
I tried ar_2_model.loglike(), but I could not figure out what kind of parameters to pass to it.
I want to get the value of the log-likelihood function of ar_2_model as similar to if I would have used
ar_3_model = ARMA(data. order=(2,0)).fit()
ll_f = ar_3_model.llf
You can still use llf:
ar_2_model = ARIMA(data, order=(2,0,0) ).fit()
print(ar_2_model.llf)

Robust Standard Errors in spatial error models

I am fitting a Spatial Error Model using the errorsarlm() function in the spdep library.
The Breusch-Pagan test for spatial models, calculated using the bptest.sarlm() function, suggest the presence of heteroskedasticity.
A natural next step would be to get the robust standard error estimates and update the p-values. In the documentation of the bptest.sarlm() function says the following:
"It is also technically possible to make heteroskedasticity corrections to standard error estimates by using the “lm.target” component of sarlm objects - using functions in the lmtest and sandwich packages."
and the following code (as reference) is presented:
lm.target <- lm(error.col$tary ~ error.col$tarX - 1)
if (require(lmtest) && require(sandwich)) {
print(coeftest(lm.target, vcov=vcovHC(lm.target, type="HC0"), df=Inf))}
where error.col is the spatial error model estimated.
Now, I can easily adapt the code to my problem and get the robust standard errors.
Nevertheless, I was wondering:
What exactly is the “lm.target” component of sarlm objects? I can not find any mention to it in the spdep documentation.
What exactly are $tary and $tarX? Again, it does not seem to be mentioned on the documentation.
Why documentation says it is "technically possible to make heteroskedasticity corrections"? Does it mean that proposed approach is not really recommended to overcome issues of heteroskedasticity?
I report this issue on github and had a response by Roger Bivand:
No, the approach is not recommended at all. Either use sphet or a Bayesian approach giving the marginal posterior distribution. I'll drop the confusing documentation. tary is $y - \rho W y$ and similarly for tarX in the spatial error model case. Note that tary etc. only occur in spdep in documentation for localmoran.exact() and localmoran.sad(); were you using out of date package versions?

What is the `node_dim` argument referring to in the message passing class?

In the PyTorch geometric tutorial for creating Message Passing Networks they have this paragraph at the start when explaining what the class does:
MessagePassing(aggr="add", flow="source_to_target", node_dim=-2): Defines the aggregation scheme to use ("add", "mean" or "max") and the flow direction of message passing (either "source_to_target" or "target_to_source"). Furthermore, the node_dim attribute indicates along which axis to propagate.
I don't understand what this node_dim is referring to, and why it is -2. I have looked at the documentation for the MessagePassing class and it says there that it is the axis which to propagate -- this still doesn't really clarify what we are doing here and why the default is -2 (presumably that is how you propagate information at a node level). Could someone offer some explanation of this to me please?
After referring to here and here, I think the thing related to it is the output of the 'message' function.
In most cases, the shape of the output is [edge_num, emb_out], and if we set the node_dim as -2, it means that we will aggregate along the edge_num using indices of the target nodes.
This is exactly the process that aggregates the information from source nodes.
The result after aggregation is [node_num, emb_out].

Bootstapping hazard rates with non-linear interpolators

I have been using QuantLib 1.6.2 to bootstrap the hazard rates from a CDS
curve. My code is similar to the example "CDS.cpp" that comes with the
QuantLib distribution, i.e.,
boost::shared_ptr<PiecewiseDefaultCurve<HazardRate, BackwardFlat> >
hazardRateStructure(new PiecewiseDefaultCurve<HazardRate, BackwardFlat>
(todaysDate, instruments, Actual365Fixed()));
I tried to experiment with different non-linear interpolation methods (instead of BackwardFlat listed above) such as:
CubicNaturalSpline
KrugerCubic
Parabolic
FritschButlandCubic
MonotonicParabolic
but I am getting the error "no appropriate default constructor available". What is the proper way of passing one of these interpolators to the
PiecewiseDefaultCurve class?
Thank you,
Chris
[Note: in case someone stumbles on this question, I'm copying here the answer I gave you on the QuantLib mailing list.]
The classes you're listing are the actual interpolation classes, but the curve is expecting a corresponding factory class (for instance, BackwardFlat in the example is the factory for the BackwardFlatInterpolation class). In the case of cubic interpolations, you'll have to use the Cubic class. By default, it builds Kruger interpolations (I'm not aware of the reason for the choice) so if you write:
PiecewiseDefaultCurve<HazardRate, Cubic>(todaysDate, instruments, Actual365Fixed())
you'll get a curve using the KrugerCubic class. To get the other interpolations, you can pass a Cubic instance with the corresponding parameters (you can look them up in the constructors of the interpolation classes); for instance,
PiecewiseDefaultCurve<HazardRate, Cubic>(todaysDate, instruments, Actual365Fixed(),
1e-12, Cubic(CubicInterpolation::Spline, false))
will give you a curve using the CubicNaturalSpline class, and
PiecewiseDefaultCurve<HazardRate, Cubic>(todaysDate, instruments, Actual365Fixed(),
1e-12, Cubic(CubicInterpolation::Parabolic, true))
will use the MonotonicParabolic class.

Bio.PDB.Superimposer - what is RMS?

I am comparing two structures and a bit confused about meaning of the result parameters:
What is the value returned saved in super_imposer.rms ?
I guess it's RMSD, but why is it not written as such?
super_imposer.rms is indeed the root-mean-square deviation.
If you consult the source of Bio.PDB.Superimposer, you'll see that the rms attribute is the result of a call to get_rms(). The docstring for get_rms() reads:
Root mean square deviation of superimposed coordinates.
The Tutorial does say that "The RMSD is stored in the rmsd attribute," however. No idea why this discrepancy exists.

Resources