-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About get_coef in older version #276
Comments
Hello @kennis222, Thank you for opening the issue, a similar example works for me in version 0.4.3, here is: # Libraries
# ==============================================================================
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skforecast.ForecasterAutoregMultiOutput import ForecasterAutoregMultiOutput
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
# Create and fit forecaster
# ==============================================================================
y = pd.Series(list(range(50)))
forecaster = ForecasterAutoregMultiOutput(
regressor = LinearRegression(),
steps = 5,
lags = 2
)
forecaster.fit(y=y)
# Get coef for step 1
# ==============================================================================
display(forecaster.get_coef(step=1))
# Get list of df
# ==============================================================================
coef_ = []
for i in list(range(forecaster.steps)):
df = forecaster.get_coef(step=i+1) # First step is 1 not 0
coef_.append(df)
# print Get coef for step 1
display(coef_[0]) From
From list:
FYI, the So in the latest version, 0.5.1 it would be: Note that # Libraries
# ==============================================================================
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from skforecast.ForecasterAutoregDirect import ForecasterAutoregDirect
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
# Create and fit forecaster
# ==============================================================================
y = pd.Series(list(range(50)))
forecaster = ForecasterAutoregDirect(
regressor = LinearRegression(),
steps = 5,
lags = 2
)
forecaster.fit(y=y)
# Get coef for step 1
# ==============================================================================
display(forecaster.get_feature_importance(step=1))
# Get list of df
# ==============================================================================
coef_ = []
for i in list(range(forecaster.steps)):
df = forecaster.get_feature_importance(step=i+1) # First step is 1 not 0
coef_.append(df)
# print Get coef for step 1
display(coef_[0]) From
From list:
I recommend using the latest version as we have fixed some bugs and improved efficiency. 😄 Thank you! |
Hello @JavierEscobarOrtiz, Thank you for the reply, but the case you show me in the version 0.4.3 still not works for my environment. However, since merging the the method coef_ or feature_importances_ depending on the type of the regressor, can I understand in this way: if using LinearRegression, the feature_importances_ means the coefficients, but if using the random forest, the feature_importances_ means the impurity-based feature importance? If "Yes", I can directly use the latest version : ) |
Hi @kennis222, |
Hi developers,
The function "get_coef" is deprecated since version 4.3.0, but I would like to use the get_coef with an older version since it easier to interpret to people without machine learning or statistical knowledge compared to use the "impurity-based feature importance" . However, when I use the function "get_coef" in the older version either 4.2.0 or 4.1.0, the program reports error with "AttributeError: 'ForecasterAutoregMultiOutput' object has no attribute 'get_coef'"
Here is the codes I calls for the function:
coef_ = []
for i,j in zip(range(1,7),pd.date_range(start='2022-01',periods=6,freq='M')):
<space>df = pd.DataFrame()
<space>df['feature'] = model_direct.get_coef(step=i)['feature']
<space>df['coef'] = model_direct.get_coef(step=i)['coef']
<space> df['date'] = pd.to_datetime(j)
<space>coef_.append(df)
Thanks.
The text was updated successfully, but these errors were encountered: