<commit_before><commit_msg>DOC: add poly fit example with regression<commit_after>"""
Polynomial Fit Plot with Regression Transform
=============================================
This example shows how to overlay data with multiple fitted polynomials using
the regression transform.
"""
# category: scatter plots

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

# Generate some random data
rng = np.random.RandomState(1)
x = rng.rand(40) ** 2
y = 10 - 1. / (x + 0.1) + rng.randn(40)
source = pd.DataFrame({'x': x, 'y': y})

# Define the degree and color of the polynomial fits
degree_list = [1, 3, 5]
color_list = ['#5276A7', '#F18727', '#E0575A']

base = alt.Chart(source).mark_circle(color='black').encode(
    alt.X('x'), alt.Y('y')
)

polynomial_fit = (base.transform_regression('x', 'y', method='poly', order=order)
                  .mark_line(color=color) 
                  for order, color in zip(degree_list, color_list))

alt.layer(base, *polynomial_fit)
{'fraction_non_alphanumeric': 0.17604912998976457, 'fraction_numerical': 0.028659160696008188, 'mean_word_length': 4.373626373626373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4808207', 'n_tokens_mistral': 339, 'n_tokens_neox': 309, 'n_words': 98}