Git Product home page Git Product logo

Comments (7)

matthewwardrop avatar matthewwardrop commented on July 19, 2024

Hi @petrhrobar ,

Formulaic already supports poly (orthogonal polynomial) and bs (basis splines) bases. Which additional spline bases do you need?

from formulaic.

petrhrobar avatar petrhrobar commented on July 19, 2024

Hey There,

COOL!. I was not aware of this. Is there any form of documentation covering the poly and bsfeatures?

from formulaic.

matthewwardrop avatar matthewwardrop commented on July 19, 2024

Online documentation is a weak point... but we'll get there. Currently the only documentation is the grammar documentation, which indicates that support exists: https://matthewwardrop.github.io/formulaic/concepts/grammar/#transforms.

The API for these transforms is the same as patsy/R, and the inline documentation is thorough (e.g. https://github.com/matthewwardrop/formulaic/blob/main/formulaic/transforms/basis_spline.py#L37). The website documentation needs to be updated, but I already know this so I'll close this out for now :).

from formulaic.

petrhrobar avatar petrhrobar commented on July 19, 2024

Thanks for that.

Just a follow-up - how to change degrees of freedom in string formula:

import seaborn as sns
from formulaic import Formula, formula
df = sns.load_dataset("tips")


Formula("total_bill ~ bs(size, df = 10)").get_model_matrix(df)

If I call the function itself, it works. however, having it changeable in the string is what I would like:

from formulaic.transforms import basis_spline, poly
pd.DataFrame(basis_spline(df['size'], degree = 10)).values

from formulaic.

matthewwardrop avatar matthewwardrop commented on July 19, 2024

Hi again!

The bs function in the formula is literally basis_spline... so you would pass the arguments through directly. For example:

from formulaic.transforms import basis_spline, poly
pd.DataFrame(basis_spline(df['size'], degree = 10)).values

would be achieved using:

from formulaic import Formula
Formula("bs(size, degree = 10)").get_model_matrix(df)

Does this not work for you?

from formulaic.

matthewwardrop avatar matthewwardrop commented on July 19, 2024

Ah... I see. There's a bug in the stateful evaluation that attempts to treat the 10 constant as a column to be evaluated. I'll resolve that ahead of the next release!

from formulaic.

matthewwardrop avatar matthewwardrop commented on July 19, 2024

The issue above was due to a bug / issue in astor <0.8. I bumped the dependency, and things should work now on the master branch; soon to be 0.3.4.

from formulaic.

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.