Giter VIP home page Giter VIP logo

Comments (3)

JoaquinAmatRodrigo avatar JoaquinAmatRodrigo commented on May 18, 2024 1

Hi @kennis222,
Yes, you understood it well :)

from skforecast.

JavierEscobarOrtiz avatar JavierEscobarOrtiz commented on May 18, 2024

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 forecaster.get_coef(step=1):

feature coef
0 lag_1 0.5
1 lag_2 0.5

From list:

feature coef
0 lag_1 0.5
1 lag_2 0.5

FYI, the get_coef method was deprecated because it was merged into the get_feature_importance method. get_feature_importance accesses the method coef_ or feature_importances_ depending on the type of the regressor.

So in the latest version, 0.5.1 it would be:

Note that ForecasterAutoregMultiOutput has been renamed to ForecasterAutoregDirect

# 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 forecaster.get_feature_importance(step=1):

feature importance
0 lag_1 0.5
1 lag_2 0.5

From list:

feature importance
0 lag_1 0.5
1 lag_2 0.5

I recommend using the latest version as we have fixed some bugs and improved efficiency. 😄

Thank you!

from skforecast.

kennis222 avatar kennis222 commented on May 18, 2024

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 : )

from skforecast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.