2

I am trying to get the Altair regression line parameters in a variable, but I can't quite figure out how to do it.

I managed to show them on my plot, but I can't access them in any other way.

I read this post, but after trying to use the altair_transform package, i get the following error:

NotImplementedError: transform of type <class 'altair.vegalite.v4.schema.core.RegressionTransform'>

Is there any other way of getting these values?

Thanks in advance!

Here is the code from the post I linked above:

import altair as alt
import pandas as pd
import numpy as np
import altair_transform

np.random.seed(42)
x = np.linspace(0, 10)
y = x - 5 + np.random.randn(len(x))

df = pd.DataFrame({'x': x, 'y': y})
chart = alt.Chart(df).mark_point().encode(
    x='x',
    y='y'
)

b  = chart.transform_regression('x', 'y', params=True).mark_line()
print(altair_transform.extract_data(b))

My version of altair_transform is 0.3.0.dev0

joelostblom
  • 43,590
  • 17
  • 150
  • 159
Eboyer
  • 85
  • 1
  • 6
  • please post the code, that will help to reproduce your error. – simpleApp Jun 02 '21 at 16:15
  • I had the same issue as you with altair_transform 0.2.0, but the example code above works for me after doing `pip install git+https://github.com/altair-viz/altair-transform.git`. I see you say that you are already on 0.3.0dev0, so just double checking that you have tried restarting your kernel since you installed altair_transform from GitHub directly. – joelostblom Jun 02 '21 at 16:57
  • I just pasted the code you provided above and it prints the parameters as expected. Tested on linux in jupyterLab with python 3.9.4, altair 4.1.0 and altair-transform 0.3.0.dev0. – roble Jun 02 '21 at 20:47

0 Answers0