rpy2: compatibiliity issue 2.0.6 vs 2.3.8 - rpy2

The following works in rpy2 2.0.6:
robjects.r('M = lm(...)')
M = robjects.r('M')
coefficients = M.r['coefficients'][0]
But after I upgraded to rpy2 2.3.8, the above fails with the message
AttributeError: 'ListVector' object has no attribute 'r'
What do I need to change to make this work in 2.3.8?

I am not certain that the code snippet you provide worked with rpy2-2.0.x
The documentation, section Introduction, is showing how to extract coefficients from linear models:
http://rpy.sourceforge.net/rpy2/doc-2.1/html/introduction.html#linear-models

Related

Spacy returns "AttributeError: 'spacy.tokens.doc.Doc' object has no attribute 'spans'" in simple .spans assignment. Why?

I'm just trying to mark subparts of a document as spans as per Spacy's documentation
import spacy
nlp = spacy.load('en_core_web_sm')
sentence = "The car with the white wheels was being confiscated by the police when the owner returns from robbing a bank"
doc = nlp(sentence)
doc.spans['remove_parts'] = [doc[2:6], doc[9:12]]
doc.spans['remove_parts']
This looks pretty straight forward, but Spacy returns the following error (and attributes it to the second line i.e. the assignment):
AttributeError: 'spacy.tokens.doc.Doc' object has no attribute 'spans'
I can't see what's going on at all. Is this a Spacy bug? Has spans property been removed even though it is still in the documentation? If not what am I missing?
PD: I'm using Colab for this. And spacy.info shows:
spaCy version 2.2.4
Location /usr/local/lib/python3.7/dist-packages/spacy
Platform Linux-4.19.112+-x86_64-with-Ubuntu-18.04-bionic
Python version 3.7.10
Models en
This code:
nlp = English()
text = "The car with the white wheels was being confiscated by the police when the owner returns from robbing a bank"
doc = nlp(text)
doc.spans['remove_parts'] = [doc[2:6], doc[9:12]]
doc.spans['remove_parts']
should work correctly from spaCy v3.0 onwards. If it doesn't - can you verify that you are in fact running the code from the correct virtual environment within colab (and not a different environment using spaCy v2)? We have previously seen issues where Colab would still be accessing older installations of spaCy on the system, instead of sourcing the code from the correct venv. To double check, you can try running the code in a Python console directly instead of through Colab.

'OneHotEncoder' object has no attribute 'get_feature_names'

I am trying to extract the features using the get_feature_names function of the OneHotEncoder object of scikit learn but its is throwing me an error saying
"'OneHotEncoder' object has no attribute 'get_feature_names'".
Below is the code snippet
# Creating the object instance for label encoder
encoder = OneHotEncoder(sparse=False)
onehot_encoded = encoder.fit_transform(df[data_column_category])
onehot_encoded_frame = pd.DataFrame(onehot_encoded,columns = encoder.get_feature_names(data_column_category))
Apparently, it has been renamed to get_feature_names_out.
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html#sklearn.preprocessing.OneHotEncoder.get_feature_names_out
That feature was introduced recently, so you might just need to update your sklearn version.
You can do it as follows:
pip install -U scikit-learn

module 'statsmodels.tsa.api' has no attribute 'arima_model'

I'm trying to use "statsmodels.api" to work with time series data and trying to fit a simple ARIMA model using
sm.tsa.arima_model.ARIMA(dta,(4,1,1)).fit()
but I got the following error
module 'statsmodels.tsa.api' has no attribute 'arima_model'
I'm using 'statsmodels' version 0.9.0 with 'spyder' version 3.2.8 I'd be pleased to get your help thanks
The correct path is :
import statsmodels.api as sm
sm.tsa.ARIMA()
You can view it using a shell that allows autocomplete like ipython.
It is also viewable in the example provided by statsmodels such as this one.
And more informations about package structure may be found here.

Python cv2.boost() error

I was working on Computer Vision in Python. I have to use the AdaBoost algorithm for a purpose.
OpenCV has a function :
cv2.Boost([trainData, tflag, responses[, varIdx[, sampleIdx[, varType[, missingDataMask[, params]]]]]])
which I used like this: model = cv2.Boost(X,cv2.CV_ROW_SAMPLE,Y)
where X is the training data and Y is the response
This is the error which shows up: module 'cv2.cv2' has no attribute 'Boost'
I tried searching for relevant documentation which indexes the function Boost but this error keeps showing up which make no sense
I'm using OpenCV version 3.2.0 and Python version 3.6.1

AttributeError: module 'tensorflow' has no attribute 'streaming_accuracy'

accuracy = tf.streaming_accuracy (y_pred,y_true,name='acc')
recall = tf.streaming_recall (y_pred,y_true,name='acc')
precision = tf.streaming_precision(y_pred,y_true,name='acc')
confusion = tf.confuson_matrix(Labels, y_pred,num_classes=10,dtype=tf.float32,name='conf')
For the above code, I have received the same error in past few days.
Isn't the syntax same as it is in the API documentation for tensorflow?
try to use this instead (in a fresh python file, I would suggest create a /tmp/temp.py and run that)
from tensorflow.contrib.metrics import streaming_accuracy
and if this doesn't work then
either there is an installation problem (In which case reinstall)
or you are importing the wrong tensorflow module.

Resources