Here is what I did:

Code: Select all

```
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
X = np.random.randn(10000, 2)
y = np.zeros(10000)
df = pd.DataFrame(data=X,
index=np.arange(10000),
columns=[['x1', 'x2']])
```

First, I tried the same way the instructor shows us, with apply() function:

Code: Select all

```
def x1_2(row):
return row['x1']**2
df['x1_2'] = df.apply(x1_2, axis=0)
```

Second, I searched into Pandas documentation, as instructed, then I tried:

Code: Select all

```
df['x1_2'] = df['x1']**2
df['x2_2'] = df['x2']**2
df['x1x2'] = df['x1']*df['x2']
```

Any ideas about how to perform the quadratic feature expansion (i.e. generate 3 new columns containing x1^2, x2^2 and x1*x2?