Importing & using HoltWinters from hardPredictions - python

I'm stuck on importing a module from hardPredictions. I can find documentation on installing the libraryand using the module module, but not how to import the module.
I've tried the following:
from hardPredictions import HoltWinters
model = HoltWinters()
This gives me an error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-72e6928695cf> in <module>
----> 1 model = HoltWinters()
TypeError: 'module' object is not callable
This works, but then I can't pass my ts to the model:
from hardPredictions import HoltWinters
model = HoltWinters
model.fit(ts)
gives an error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-f40ff401465a> in <module>
1 model = HoltWinters
----> 2 model.fit(ts)
AttributeError: module 'hardPredictions.HoltWinters' has no attribute 'fit'
I've also tried running help() and dir() on HoltWinters, but think the main thing is I'm lacking the skill to ask the library how to import a model. Your advice is much appreciated!

Related

How to get the list of all Datasets available on Kaggle using the Kaggle API with Python/

I am trying to get the list of all datasets in Kaggle using the Kaggle API but am getting some errors.
This is what I tried:
from kaggle.api.kaggle_api import KaggleApi
api = KaggleApi("/content/drive/MyDrive/C.S/Kaggle/kaggle.json")
api.datasets_list()
Error:
AttributeError Traceback (most recent call last)
<ipython-input-28-e4128a2ad298> in <module>()
2
3 api = KaggleApi("/content/drive/MyDrive/C.S/Kaggle/kaggle.json")
----> 4 api.datasets_list()
AttributeError: 'str' object has no attribute 'select_header_accept'

NameError: name 'FaceDetector' is not defined

I was trying to run this code but it says
NameError Traceback (most recent call last)
<ipython-input-5-49e303967177> in <module>
3
4 #Detector object created
----> 5 fd=FaceDetector(frontal_cascade_path)
NameError: name 'FaceDetector' is not defined
This is the code: -
#Frontal face of haar cascade loaded
frontal_cascade_path="../input/haarcascade-frontal-faces/haarcascade_frontalface_default.xml"
#Detector object created
fd=FaceDetector(frontal_cascade_path)
Read this. You need to import the FaceDetector into your code:
from face_detector import FaceDetector

"module 'torchtext.data' has no attribute 'Field'"

import torchtext
ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-2a3d11c77e7d> in <module>
----> 1 ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
AttributeError: module 'torchtext.data' has no attribute 'Field'
It won't import torchtext.data.Field for some reason even though that's whats in the docs
[BC Breaking] Legacy
In v0.9.0 release, we move the following legacy code to torchtext.legacy. This is part of the work to revamp the torchtext library and the motivation has been discussed in Issue #664:
torchtext.legacy.data.field
torchtext.legacy.data.batch
torchtext.legacy.data.example
torchtext.legacy.data.iterator
torchtext.legacy.data.pipeline
torchtext.legacy.datasets
We have a migration tutorial to help users switch to the torchtext datasets in v0.9.0 release. For the users who still want the legacy components, they can add legacy to the import path.
Try it with ENGLISH = torchtext.legacy.data.field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")

I can import function but not class with error "AttributeError: module 'XXXX' has no attribute 'YYYY' "

I can't load class I defined in another file. It is strange behavior that I CAN load function defined in the same file.
XXXX.py
def hoge():
print('hoge')
class YYYY:
def hoge(self):
print('hoge')
I try to import and run XXXX as follow:
import XXXX
XXXX.hoge()
XXXX.YYYY
Then, I encountered the error
hoge
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-76-cbd9d0cb0faf> in <module>
2 XXXX.hoge()
----> 3 XXXX.YYYY
AttributeError: module 'XXXX' has no attribute 'YYYY'
I use Python 3.6
I've solved this problem.
This error occurs on jupyter-notebook.
But it works on terminal.
I don't know why this happens on jupyter.

How do you add an attribute to a django app python module?

Given a django app called mattermost which has a model called Channel we can do something like this.
import mattermost
for channel in Channel.objects.all():
print(channel)
I'd like to be able to do something like this
import mattermost
mattermost.channels.list
I've tried adding channels.py with a def list(): function in the same folder as mattermost/init.py.
I'm getting the following error.
In [7]: reload(mattermost)
Out[7]: <module 'mattermost' from '/home/csmu/mipgen-django/mattermost/__init__.py'>
In [8]: mattermost.channels.list
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-d4715777f4f1> in <module>()
----> 1 mattermost.channels.list
AttributeError: module 'mattermost' has no attribute 'channels'
How do you add an attribute to a django app python module?
The contents of channels.py:
import mattermost
def list():
for channel in mattermost.models.Channel.objects.all():
print(channel)
Try
from mattermost import channels
print(channels.list())
This resulted in:
In [1]: import mattermost
In [2]: mattermost.channels.list()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-249466f32547> in <module>()
----> 1 mattermost.channels.list()
AttributeError: module 'mattermost' has no attribute 'channels'
In [3]: from mattermost import channels
In [4]: mattermost.channels.list()
list.stub
In [5]:
which is close.
I discovered you can do this by adding the following to mattermost/__init__py
#!/usr/bin/env python
import os, pkgutil
__all__ = list(module for _, module, _ in
pkgutil.iter_modules([os.path.dirname(__file__)]))
then the following works
import mattermost
from mattermost import *
mattermost.channels.list()
which produces output for each mattermost channel.

Categories

Resources