<jupyter_start><jupyter_text>Title : Ex: Polynomial Regression - Goal:  Create cubic polynomial least-squares regression DescriptionAfter fitting the model and getting the predictions, you should see the following plot:  Hints: Formulas in statsmodelssm.olsnumpy vanderRefer to lecture notebook.Do not change any other code except the blanks.<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

import statsmodels.formula.api as sm

%matplotlib inline 
df = pd.read_csv('data1.csv')
df = df.sort_values('x')
df.head()
plt.scatter(df.x, df.y);
plt.xlabel("x")
plt.ylabel("y")
plt.show()<jupyter_output><empty_output><jupyter_text>Cubic polynomial least-squares regression of y on x<jupyter_code>### edTest(test_ols_formula) ###
def fit_model(formula):
    return sm.ols(formula=formula, data=df).fit()

formula = _____ 
fit2_lm = fit_model(formula)
### edTest(test_predictions_summary) ###
#Get the predictions and the summary dataframe
poly_predictions = fit2_lm.______().___()   
poly_predictions
ax2 = df.plot.scatter(x='x',y='y',c='Red',title="Data with least-squares cubic fit")
ax2.set_xlabel("x")
ax2.set_ylabel("y")

# CI for the predection at each x value, i.e. the curve itself
ax2.plot(df.x, poly_predictions['mean'],color="green")
ax2.plot(df.x, poly_predictions['mean_ci_lower'], color="blue",linestyle="dashed")
ax2.plot(df.x, poly_predictions['mean_ci_upper'], color="blue",linestyle="dashed");<jupyter_output><empty_output><jupyter_text>Condition number<jupyter_code>c = np.vander(_, _, increasing=True)
np.linalg.cond(c)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13258286429018137, 'fraction_numerical': 0.005628517823639775, 'mean_word_length': 7.205128205128205, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '509601', 'license': 'MIT', 'n_tokens_mistral': 585, 'n_tokens_neox': 561, 'n_words': 126, 'path': 'docs/lectures/lecture02/notebook/L1_1.ipynb', 'repo_name': 'DavidAssaraf106/2021-CS109B', 'size': '1599'}