<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <h4>Hands-on
Step1:  <h4>Training and Evaluation Set</h4>
Training Set 1
Step2:  Test 1
Step3:  Test 1
<ASSISTANT_TASK:>
Python Code:
def quad_func (x):
    return 5 * x ** 2 -23 * x + 47
# Training Set + Eval Set: 200 samples (70%, 30% split)
# Test Set: 60 samples
# Total: 260 samples
np.random.seed(5)
samples = 260
x_vals = pd.Series(np.random.rand(samples) * 20)
x2_vals = x_vals ** 2
y_vals = x_vals.map(quad_func)
y_noisy_vals = y_vals + np.random.randn(samples) * 50
df = pd.DataFrame({'x': x_vals, 
                   'x2': x2_vals ,
                   'y': y_vals, 
                   'y_noisy': y_noisy_vals})
df.head()
df.corr()
fig = plt.figure(figsize = (12, 8))
plt.scatter(x = df['x'],
            y = df['y'],
            color = 'r',
            label = 'y',)
plt.scatter(x = df['x'],
            y = df['y_noisy'],
            color = 'b',
            label = 'y noisy', 
            marker = '+')
plt.xlabel('x')
plt.ylabel('Target Attribute')
plt.grid(True)
plt.legend()
data_path = '..\Data\RegressionExamples\quadratic'
df.to_csv(os.path.join(data_path,'quadratic_example_all.csv'),
          index = True,
          index_label = 'Row')
Explanation: <h4>Hands-on: Linear Regression - Complex Shapes</h4>
<b>Test 1</b><br>
Input Features: x<br>
Output / Target: y_noisy<br>
Objective: Underfitting demo
<b>Test 2</b><br>
Input Features: x, x^2<br>
Output / Target: y_noisy<br>
Objective: How adding relevant features improves predicting accuracy<br>
End of explanation
df[df.index < 200].to_csv(os.path.join(data_path, 'quadratic_example_train_underfit.csv'),
                          index = True,
                          index_label = 'Row', 
                          columns = ['x', 'y_noisy'])
df[df.index < 200].to_csv(os.path.join(data_path, 'quadratic_example_train_normal.csv'),
                          index = True,
                          index_label = 'Row',
                          columns= ['x', 'x2', 'y_noisy'])
df.to_csv(os.path.join(data_path, 'quadratic_example_test_all_underfit.csv'), 
          index = True,
          index_label = 'Row', 
          columns = ['x'])
df.to_csv(os.path.join(data_path, 'quadratic_example_test_all_normal.csv'),
          index = True,
          index_label = 'Row', 
          columns = ['x', 'x2'])
# Pull Predictions
# Prediction without quadratic term
df = pd.read_csv(os.path.join(data_path,'quadratic_example_all.csv'), 
                 index_col = 'Row')
df_predicted_underfit = pd.read_csv(os.path.join(data_path, 'output_underfit',
                                                 'bp-pNYIAR35aSV-quadratic_example_test_all_underfit.csv.gz'))
df_predicted_underfit.columns = ["Row", "y_predicted"]
fig = plt.figure(figsize = (12, 8))
plt.scatter(x = df.x,
            y = df.y_noisy,
            color = 'b',
            label = 'actual', 
            marker = '+')
plt.scatter(x = df.x,
            y = df_predicted_underfit.y_predicted ,
            color = 'g',
            label = 'Fit (x)',
            marker = '^')
plt.title('Quadratic - underfit')
plt.xlabel('x')
plt.ylabel('Target Attribute')
plt.grid(True)
plt.legend()
Explanation: <h4>Training and Evaluation Set</h4>
Training Set 1: RowNumber, x, y_noisy<br>
Training Set 2: RowNumber, x, x ** 2, y_noisy
End of explanation
fig = plt.figure(figsize = (12, 8))
plt.boxplot([df.y_noisy, df_predicted_underfit.y_predicted], 
            labels = ['actual','predicted-underfit'])
plt.title('Box Plot - Actual, Predicted')
plt.ylabel('y')
plt.grid(True)
df.y_noisy.describe()
df_predicted_underfit.y_predicted.describe()
df_predicted_normal = pd.read_csv(os.path.join(data_path,'output_normal',
                                               'bp-In6EUvWaCw2-quadratic_example_test_all_normal.csv.gz'))
df_predicted_normal.columns = ["Row", "y_predicted"]
fig = plt.figure(figsize = (12, 8))
plt.scatter(x = df.x,
            y = df.y_noisy,
            color = 'b',
            label = 'actual', 
            marker ='+')
plt.scatter(x = df.x,
            y = df_predicted_underfit.y_predicted,
            color = 'g',
            label = 'Fit (x)',
            marker = '^')
plt.scatter(x = df.x ,
            y = df_predicted_normal.y_predicted ,
            color = 'r',
            label = 'Fit (x,x^2)')
plt.title('Quadratic - normal fit')
plt.grid(True)
plt.xlabel('x')
plt.ylabel('Target Attribute')
#plt.legend()
Explanation: Test 1:
Training RMSE: 385.18, Evaluation RMSE: 257.89, Baseline RMSE: 437.31
Wojciech results:
Training RMSE: 385.16, Evaluation RMSE: 257.898, Baseline RMSE: 437.311
RMSE for the model is large and closer to baseline
End of explanation
fig = plt.figure(figsize = (12, 8))
plt.boxplot([df.y_noisy,df_predicted_underfit.y_predicted, df_predicted_normal.y_predicted], 
            labels = ['actual','predicted-underfit','predicted-normal'])
plt.title('Box Plot - Actual, Predicted')
plt.ylabel('y')
plt.grid(True)
df_predicted_underfit.head()
df_predicted_normal.head()
Explanation: Test 1:
Training RMSE: 385.16, Evaluation RMSE: 257.89, Baseline RMSE: 437.31
Test 2:
Training RMSE: 132.20, Evaluation RMSE: 63.68, Baseline RMSE: 437.31
Test 2 RMSE is much better compared to baseline. Do note that we added approx -50 to 50 noise value to y
End of explanation
<END_TASK>