Error: module 'MSGARCH' has no attribute 'predict' - python

I am using the package rpy2 to use R language in Python environment. I am using the MSGARCH package which is only on R. The package is clearly suppose to come with the attribute predict.
https://rdrr.io/cran/MSGARCH/man/predict.html
I don't understand why I have this error. Do you have an idea please?
the full error message is :
Traceback (most recent call last):
File "markov.py", line 165, in <module>
pred = ms.predict(object = fitMCMC, newdata = None, nahead = '30L')
AttributeError: module 'MSGARCH' has no attribute 'predict'
The code is:
ms = importr('MSGARCH')
from rpy2.robjects import r, pandas2ri, numpy2ri, vectors
pandas2ri.activate()
numpy2ri.activate()
base = importr('base')
stats = importr('stats')
pred = ms.predict(object = fitMCMC, newdata = None, nahead = '30L')

Related

AttributeError: 'Point' object has no attribute 'point'

I am transforming a point from source frame to target frame using tf2. Below is the code snippet:
import tf2_ros
import tf2_geometry_msgs
transform = tf_buffer.lookup_transform(target_frame, source_frame, rospy.Time(0), rospy.Duration(1.0))
pose_transformed = tf2_geometry_msgs.do_transform_point(point_wrt_kinect, transform)
print pose_transformed
The code throws following error:
Traceback (most recent call last):
File "q1.py", line 29, in <module>
pose_transformed = tf2_geometry_msgs.do_transform_point(point_wrt_kinect, transform)
File "/opt/ros/indigo/lib/python2.7/dist-packages/tf2_geometry_msgs/tf2_geometry_msgs.py", line 59, in do_transform_point
p = transform_to_kdl(transform) * PyKDL.Vector(point.point.x, point.point.y, point.point.z)
AttributeError: 'Point' object has no attribute 'point'
The tf_geometry_msgs.py can be seen online at here. This seems silly as they are calling point.point.x.
Which point are they talking about? I believe it should be geometry_msgs/Point, which I declared in the following way:
from geometry_msgs.msg import Point
point_wrt_kinect = Point()
point_wrt_kinect.x = -0.41
point_wrt_kinect.y = -0.13
point_wrt_kinect.z = 0.77
Any workaround, please?
do_transform_point(point_wrt_kinect, transform)
point_wrt_kinect is the object of Point class. In documentation it should be PointStamped class object. its the error of documentation.
you have to create object of PointStamped class instead of Point class.

'NoneType' object has no attribute 'fileno'

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
plt.style.use('ggplot')
columns = ['user_id','order_dt','order_products','order_amount']
df = pd.read_csv('CDNOW_master.txt',names = columns,sep = '\s+')
df['order_date'] = pd.to_datetime(df.order_dt,format='%Y%m%d')
df['month'] = df.order_date.values.astype('datetime64[M]')
f = df.groupby('user_id')['month'].min().value_counts()
print(f)
Above is my code,my purpose is to get the value_counts of the users purchased in their first month, but only got the result of 'NoneType' object has no attribute 'fileno'.
any ideas? much appreciate
here are the traceback
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\practice\CDNOW.py", line 19, in <module>
print(f)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\base.py", line 51, in __str__
return self.__unicode__()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\core\series.py", line 982, in __unicode__
width, height = get_terminal_size()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pandas\io\formats\terminal.py", line 33, in get_terminal_size
return shutil.get_terminal_size()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\shutil.py", line 1071, in get_terminal_size
size = os.get_terminal_size(sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'
I am seeing this as well.
>>> type(sys.__stdout__)
<class 'NoneType'>
I get NoneType when calling dunder stdout while I am using idle. I assume that pandas wants to determine how much to display in the results and is looking for the sys output information. In the documentation, it mentions what this is, but not how to reset it.
I did this:
sys.__stdout__ = sys.stdout
and it fixed the problem, but I have not idea if I caused problems down the line.
You may wish to try out the following.
df = pd.read_csv('CDNOW_master.txt',usecols = columns,sep = '\s+')
instead of
df = pd.read_csv('CDNOW_master.txt',names = columns,sep = '\s+')
This solved my problem. Hope it solves yours too.

AttributeError: 'QgsComposition' object has no attribute 'setMapCanvas'

I am trying to save map and its legends using QGis Map composer. I have already template .
Here is code in python.
layers =iface.legendInterface().layers()
canvas=iface.mapCanvas()
for layer in layers:
# myFile = r"C:\Users\craj\Downloads\GraduatedTheme.qpt"
myFile = r"C:\Users\craj\Downloads\GraduatedTheme.qpt"
myTemplateFile = file(myFile, 'rt')
myTemplateContent = myTemplateFile.read()
myTemplateFile.close()
myDocument = QDomDocument()
myDocument.setContent(myTemplateContent, False)
newcomp = iface.createNewComposer()
newcomp.composition().loadFromTemplate(myDocument)
newcomp.composition().refreshItems()
for a in iface.mapCanvas().layers():
iface.legendInterface().setLayerVisible(a, False)
iface.legendInterface().setLayerVisible(layer, True)
newcomp.composition().refreshItems()
map_item = newcomp.composition()
map_item.getComposerItemById('map')
map_item.setMapCanvas(canvas)
map_item.zoomToExtent(canvas.extent())
newcomp.composition().refreshItems()
legend_item = newcomp.composition().getComposerItemById('legend')
legend_item.updateLegend()
newcomp.composition().refreshItems()
imagePath ='C:/Users/craj/Downloads/'+layer.name()+'.png'
image = newcomp.composition().printPageAsRaster(0)
image.save(imagePath,'png')
An error has occurred while executing Python code:
AttributeError: 'QgsComposition' object has no attribute 'setMapCanvas'
Traceback (most recent call last):
File "C:/Users/craj/.qgis2/python/plugins\JoinAttribute\Join_Attribute.py", line 436, in run
map_item.setMapCanvas(canvas)
AttributeError: 'QgsComposition' object has no attribute 'setMapCanvas'
If you look at the docs there is no setMapCanvas on QgsComposition. This method is in several other classes, such as QgsComposerMap. So based on the code calling getComposerItemById() what you likely need is this:
composition = newcomp.composition()
map_item = composition.getComposerItemById('map')
map_item.setMapCanvas(canvas)

Why is python pocketsphinx giving TypeError?

I am using the Python pocket sphinx tutorial, according to
https://metakermit.com/2011/python-speech-recognition-helloworld/
(complete code here):
import sys,os
def decodeSpeech(hmmd,lmdir,dictp,wavfile):
"""
Decodes a speech file
"""
try:
import pocketsphinx as ps
import sphinxbase
except:
print """Pocket sphinx and sphixbase is not installed
in your system. Please install it with package manager.
"""
speechRec = ps.Decoder(hmm = hmmd, lm = lmdir, dict = dictp)
wavFile = file(wavfile,'rb')
wavFile.seek(44)
speechRec.decode_raw(wavFile)
result = speechRec.get_hyp()
return result[0]
if __name__ == "__main__":
hmdir = "/usr/share/pocketsphinx/model/hmm/en_US/"
lmd = "/usr/share/pocketsphinx/model/lm/en_US/hub4.5000.DMP"
dictd = "/usr/share/pocketsphinx/model/lm/en_US/cmu07a.dic"
wavfile = sys.argv[1]
recognised = decodeSpeech(hmdir,lmd,dictd,wavfile)
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
print recognised
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
and when I run it I get the following error message:
Traceback (most recent call last):
File "hello.py", line 30, in <module>
recognised = decodeSpeech(hmdir,lmd,dictd,wavfile)
File "hello.py", line 17, in decodeSpeech
speechRec = ps.Decoder(hmm = hmmd, lm = lmdir, dict = dictp)
TypeError: __init__() got an unexpected keyword argument 'hmm'
Could you help me?
Looking at the pocketsphinx code on GitHub, in decoder_test.py we have an example of how to pass options to Decoder.
So it looks like your tutorial is for an old version and you actually want:
config = ps.Decoder.default_config()
config.set_string('-hmm', hmmd)
config.set_string('-lm', lmdir)
config.set_string('-dict', dictp)
speechRec = ps.Decoder(config)

Python Code unable to execute in Windows

My python code was running successfully in Ubuntu 14.04; but when I went to run in Windows Platform, it throws me into error.
The Code:
import pymc
with open("days1.txt") as f:
dataset = map(float, f)
a = pymc.Uniform('a', lower=0, upper=1500000, value=70, doc='Weibull alpha parameter')
b = pymc.Uniform('b', lower=0, upper=1500000, value=70, doc='Weibull beta parameter')
like = pymc.Weibull('like', alpha=a, beta=b, value=dataset, observed=True)
if __name__=='__main__':
import pylab
M = pymc.MCMC([a,b,like])
M.sample(10000,5000,2)
pymc.Matplot.plot(a)
pymc.Matplot.plot(b)
M.summary()
M.write_csv("parameters1.csv")
The error:
C:\Python35-32>python.exe "E:\TCS\Desktop\EarlyWarning\JLR\Data\EJ327000AB\Scrip
ts\Screen 7\Check Python - 1\weibullEstimationOutData - 1.py"
Traceback (most recent call last):
File "C:\Python35-32\lib\site-packages\pymc\PyMCObjects.py", line 742, in __in
it__
self._value = np.array(value, dtype=dtype)
TypeError: float() argument must be a string or a number, not 'map'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\TCS\Desktop\EarlyWarning\JLR\Data\EJ327000AB\Scripts\Screen 7\Check P
ython - 1\weibullEstimationOutData - 1.py", line 8, in <module>
like = pymc.Weibull('like', alpha=a, beta=b, value=dataset, observed=True)
AttributeError: 'TypeError' object has no attribute 'message'
Kindly Help. Thanks in Advance
You are using Python 2 with Ubuntu, but Python 3 with Windows. Install Python 2 for Windows, or port your code to Python 3
import pylab
import pymc
with open("days1.txt") as f:
dataset = list(map(float, f))
a = pymc.Uniform('a', lower=0, upper=1500000, value=70, doc='Weibull alpha parameter')
b = pymc.Uniform('b', lower=0, upper=1500000, value=70, doc='Weibull beta parameter')
like = pymc.Weibull('like', alpha=a, beta=b, value=dataset, observed=True)
if __name__=='__main__':
M = pymc.MCMC([a,b,like])
M.sample(10000,5000,2)
pymc.Matplot.plot(a)
pymc.Matplot.plot(b)
M.summary()
M.write_csv("parameters1.csv")

Categories

Resources