Closed huangziwei closed 2 years ago
oops. just found out that I can just write Numpy functions within the formula!
y ~ np.cos(theta) + np.sin(theta)
does the job.
Great features!
I just hit another problem...
Formulaic raises an FactorEvaluationError when using numpy in formula with model_spec.get_model_matrix():
import numpy as np
import pandas as pd
from formulaic import model_matrix
theta = np.linspace(-np.pi, np.pi, 100)
y = 1 + theta * 2
df = pd.DataFrame(np.vstack([y, theta]).T, columns=['y', 'theta'])
Y, X = model_matrix('y ~ np.cos(theta) + np.sin(theta) - 1', data=df)
Xnew = pd.DataFrame(np.linspace(-np.pi, np.pi, 50), columns=['theta'])
X.model_spec.get_model_matrix(Xnew)
FactorEvaluationError: Unable to evaluate factor
np.cos(direction)
. [NameError: name 'np' is not defined]
maybe a dedicated transform for circular data can handle this better?
Sorry for spamming ... upgrading to 0.5.2 solved the issue...
Hello. Thank you for this great project!
I am doing some simple circular regression recently and would love to see this can be handled directly by formulaic:
y ~ circ(theta)
where
circ(theta)
transformstheta
into two columns:cos(theta)
andsin(theta)
.