Failed to Importing Adida from statsforecast.models in Python - python

I was trying to replicate this code for stat forecasting in python, I came across the issue of not being able to load this model 'adida' form statsforecast library,
Here is the link for reference : https://towardsdatascience.com/time-series-forecasting-with-statistical-models-f08dcd1d24d1
import random
from itertools import product
from IPython.display import display, Markdown
from multiprocessing import cpu_count
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from nixtlats.data.datasets.m4 import M4, M4Info
from statsforecast import StatsForecast
from statsforecast.models import (
adida,
croston_classic,
croston_sba,
croston_optimized,
historic_average,
imapa,
naive,
random_walk_with_drift,
seasonal_exponential_smoothing,
seasonal_naive,
seasonal_window_average,
ses,
tsb,
window_average
)
Attached is the error message, Can you please have a look at this and let me know why is there an issue in importing this?
Given below is the error image:

I did some research and figured out the issue is probably with the version, try installing this specific version of statsforecast
pip install statsforecasts==0.6.0
Trying loading these models after that, hopefully this should work.

As of v1.0.0 of StatsForecast, the API changed to be more like sklearn, using classes instead of functions. You can find an example of the new syntax here: https://nixtla.github.io/statsforecast/examples/IntermittentData.html.
The new code would be
from statsforecast import StatsForecast
from statsforecast.models import ADIDA, IMAPA
model = StatsForecast(df=Y_train_df, # your data
models=[ADIDA(), IMAPA()],
freq=freq, # frequency of your data
n_jobs=-1)
If you want to use the old syntax, setting the version as suggested should work.

If you have updated the package ..use ADIDA it will work
see the model list name with new packages
ADIDA(),
IMAPA(),
(SimpleExponentialSmoothing(0.1)),
(TSB(0.3,0.2)),
(WindowAverage( 6))

Related

module 'keras.layers.normalization' has no attribute 'BatchNormalizationBase'

when i run this code
import os
from autokeras import
StructuredDataClassifier
import stellargraph as sg
from stellargraph.mapper import
FullBatchNodeGenerator
from tensorflow.keras import layers,
optimizers, losses, metrics, Model
from sklearn import preprocessing,
model_selection
from IPython.display import display, HTML
import matplotlib.pyplot as plt
%matplotlib inline
i have this error
AttributeError: module 'keras.layers.normalization' has no attribute 'BatchNormalizationBase'
Knowing that this code has been run many times without any problems
In my case which had a structure like this:
I added these two lines to the__init__.py file:
from keras.layers.normalization.layer_normalization import *
from keras.layers.normalization.batch_normalization import *
And problem fixed.
restart runtime then reinstall keras library

I keep running into a problem when using scipy.stats.norm "module has no attribute norm"

I have searched through the other posts similar to this one to no avail. I have uninstalled scipy, updated conda, and re-installed scipy. At first I think I had upgraded it with pip accidentally so I removed all that and reinstalled with conda. I am still getting this error. I have done the same think in a google cloud data proc to narrow down whether the error is coming from something about my setup but I am getting the same error. Here is the function I was trying to run:
def get_ci(value, cl, sd):
loc = scs.stats.norm.ppf(1 - cl/2)
rng_val = sci.norm.cdf(loc - value/sd)
lwr_bnd = value - rng_val
upr_bnd = value + rng_val
return_val = (lwr_bnd, upr_bnd)
return(return_val)
I have tried different import statements too- including:
import scipy
from scipy import stats
import scipy as scs
from scipy import norm
from scipy.stats import norm
Thanks in advance.
Also, if you have any constructive criticism about my post I would appreciate that as well. This is my first post.
Well, the function you posted uses the name sci which is not defined in any of your import statements. Try running this in a fresh kernel.
from scipy.stats import norm
def get_ci(value, cl, sd):
loc = norm.ppf(1 - cl/2)
rng_val = norm.cdf(loc - value/sd)
lwr_bnd = value - rng_val
upr_bnd = value + rng_val
return_val = (lwr_bnd, upr_bnd)
return(return_val)
By the way, you should generally post an exact example of your code so we can run it ourselves. Since your problem is with import statements, it would include the exact import statements combined with the code. Were you actually using all five of those import statements at once and then trying to define your function?

random subspace ensemble classifier python

i am in python i search for implementation for random subspace ensemble classifier , and i found the following code in github
https://github.com/mwygoda/randomSubspaceImplementation/blob/master/solution.py
author depend in this two lib
from utils import prepare_data_from_file
from utils import plot_results
i try to install utils using pip3, it installed and worked when i run import utils as ut put still get error cannot import name 'plot_results' or'prepare_data_from_file'
any one help me how can i fix it
That file is not in the repo. You will have to implement it yourself.
from the code it looks like it returns a feature vector and target labels.
e.g
def prepare_data_from_file(file):
import pandas as pd
df = pd.read_csv(file)
return df['A'], df['B']
But this is mere speculation. Now get off stackoverflow and go do your assisgnment.

name 'ImageDataBunch' is not defined

I'm getting this error "name 'ImageDataBunch' is not defined" and am not able to find a solution on the Internet.
The full code can be found here: https://dzlab.github.io/jekyll/update/2018/11/13/audio-classification/.
np.random.seed(42)
data = ImageDataBunch.from_lists(path, fnames, labels, ds_tfms=None, size=224, bs=bs)
data.normalize(imagenet_stats)
data.show_batch(rows=5, figsize=(8,8))
I'm running this code on Google Colab and Python 3.6.
You just need to import the ImageDataBunch class from the fast.ai library. Here's the docs for it. Just add the following to the top of your code to import the entirety of the vision library classes:
from fastai.vision import *

Why can't I import statsmodels directly?

I'm certainly missing something very obvious here, but why does this work:
a = [0.2635,0.654654,0.365,0.4545,1.5465,3.545]
import statsmodels.robust as rb
print rb.scale.mad(a)
0.356309343367
but this doesn't:
import statsmodels as sm
print sm.robust.scale.mad(a)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-1ce0c872b0be> in <module>()
----> 1 print statsmodels.robust.scale.mad(a)
AttributeError: 'module' object has no attribute 'robust'
Long answer see http://www.statsmodels.org/stable/importpaths.html
Statsmodels has intentionally mostly empty __init__.py but has a parallel import collection through the api.py.
The recommended import for interactive work import statsmodels.api as sm imports almost all of statsmodels, numpy, pandas and patsy, and large parts of scipy. This is slooow on cold start.
If we want to import just a specific part of statsmodels, then we don't need to import all these extras. Having empty __init__.py means that we can import just a single module (which of course imports the dependencies of that module).
e.g. from statsmodels.robust.scale import mad or
import statmodels.robust scale as smscale
smscale.mad(...)
(Small caveat: Some of the very low level imports might not remain always backwards compatible if the internal structure changes. However, the general policy is to deprecate functions over one or two releases while maintaining the old access structure.)
You can, you just have to import robust as well:
import statsmodels as sm
import statsmodels.robust
Then:
>>> sm.robust.scale.mad(a)
0.35630934336679576
robust is a subpackage of statsmodels, and importing a package does not in general automatically import subpackages (unless the package is written to do so explicitly).

Categories

Resources