I am running the follwing code:
!pip install scikit-learn==0.24
import sklearn.metrics
mape = mean_absolute_percentage_error(target_test.values, p)
but then get an error. What is the problem with this code?
If you only need this function from sklearn.metrics it is recommended to also
import only this function by using:
from sklearn.metrics import mean_absolute_percentage_error
...
If you want to keep the syntax of your import as is, you have to call the function the following way:
mape = sklearn.metrics.mean_absolute_percentage_error(target_test.values, p)
If this is too long for you, you can import it and give it an own name:
import sklearn.metrics as skmetr
mape = skmetr.mean_absolute_percentage_error(target_test.values, p)
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))
I am trying to use function threshold from scipy package.
from scipy.stats import threshold
I_t=threshold(I, threshmin=2, threshmax=400, newval=-1) # I is an array containing image data
However, i am getting an error message saying
cannot import name 'threshold' from 'scipy.stats'
The function threshold was deprecated in SciPy 0.17.0 and removed from SciPy 1.0.0. Use numpy.clip (with arguments adjusted appropriately) instead.
when I import statsmodels.api as sm, and run sm.nonparametric.smoothers_lowess.lowess
Error occurs:
module 'statsmodels.nonparametric.api' has no attribute 'smoothers_lowess'
But import statsmodels as sm doesn't have this error.
import statsmodels.api as sm
sm.nonparametric.smoothers_lowess.lowess()
import statsmodels as sm
sm.nonparametric.smoothers_lowess.lowess()
AttributeError: module 'statsmodels.nonparametric.api' has no attribute 'smoothers_lowess'
import statsmodels as sm makes your sm refer to statsmodels -- which is to say, statsmodels/__init__.py.
import statsmodels.api as sm makes your sm refer to statsmodels.api -- which is to say, statsmodels/api.py.
Because these are different files, it is normal and expected for them to have different contents. Note that all content accessed through the api modules is public functionality, supported and stable across releases; if you use nonpublic functionality, your code may break in future releases.
The difference in rationale between the APIs is documented at https://www.statsmodels.org/dev/importpaths.html
Im trying to use the following code (example):
import pandas as pd
(import statsmodels.api as sm) - Tried adding, no luck
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
x = pd.DataFrame(imports a vector)
plot_acf(x)
There is some code in between, but the problem arises when Python tries to plot the autocorrelation using statsmodels, and returns the following error:
File "/Users/user/anaconda/lib/python3.6/site-packages/statsmodels/iolib/foreign.py",
line 20, in <module>
import statsmodels.tools.data as data_util
AttributeError: module 'statsmodels' has no attribute 'tools'
I tried reinstalling multiple libraries, but nothing seems to get me past this error. Could this be a statsmodels-side bug?