Giter Site home page Giter Site logo

Comments (5)

bashtage avatar bashtage commented on May 13, 2024

The help says:

        weights : dict-like
            Dictionary like object (e.g. a DataFrame) containing variable
            weights.  Each entry must have the same number of observations as
            data.  If an equation label is not a key weights, the weights will
            be set to unity

so that weights should be a dictionary (or possibly a DataFrame) with columns eq1 and eq2 in your case where the column has the weights for respective weights. Let me know if this works.

from linearmodels.

bashtage avatar bashtage commented on May 13, 2024

BTW, weights must be positive, so randn is a bad choice.

from linearmodels.

tra6sdc avatar tra6sdc commented on May 13, 2024

Thanks for the help. Here is the code with adaptions that work in regards to weights.

import pandas as pd
import numpy as np
np.random.seed(123)
data = pd.DataFrame(np.random.randn(500, 4), columns=['y1', 'x1_1', 'y2', 'x2_1'])
weight = abs(pd.DataFrame(np.random.randn(500, 2), columns=['eq1','eq2']))
from linearmodels.system import SUR
formula = {'eq1': 'y1 ~ 1 + x1_1', 'eq2': 'y2 ~ 1 + x2_1'}
mod = SUR.from_formula(formula, data, weights=weight)
res = mod.fit(cov_type='unadjusted')
res

Is out-of-sample prediction possible? Or, for such a simple model should I do the calculation "manually"?

from linearmodels.

bashtage avatar bashtage commented on May 13, 2024

Have a look at the help here:

https://bashtage.github.io/linearmodels/system/results.html#linearmodels.system.results.SystemResults.predict

from linearmodels.

tra6sdc avatar tra6sdc commented on May 13, 2024

Here is my final code

import pandas as pd
import numpy as np
np.random.seed(123)
data = pd.DataFrame(np.random.randn(500, 4), columns=['y1', 'x1_1', 'y2', 'x2_1'])
weight = abs(pd.DataFrame(np.random.randn(500, 2), columns=['eq1','eq2']))
from linearmodels.system import SUR
formula = {'eq1': 'y1 ~ 1 + x1_1', 'eq2': 'y2 ~ 1 + x2_1'}
mod = SUR.from_formula(formula, data, weights=weight)
res = mod.fit(cov_type='unadjusted')
data1 = pd.DataFrame(np.random.randn(500, 4), columns=['y1', 'x1_1', 'y2', 'x2_1'])
pre = res.predict(data=data1)

Thanks again.

from linearmodels.

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.