# Problem with Perceptron

Perceptron does not work with non-linear data.

## Code Example:

```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
```

```python
or_data = pd.DataFrame()
and_data = pd.DataFrame()
xor_data = pd.DataFrame()
```

```python
or_data['input1']=[1,1,0,0]
or_data['input2']=[1,0,1,0]
or_data['ouput']=[1,1,1,0]
```

```python
and_data['input1']=[1,1,0,0]
and_data['input2']=[1,0,1,0]
and_data['ouput']=[1,0,0,0]
```

```python
xor_data['input1']=[1,1,0,0]
xor_data['input2']=[1,0,1,0]
xor_data['ouput']=[0,1,1,0]
```

```python
and_data
```

```python
sns.scatterplot(x=and_data['input1'],y=and_data['input2'],hue=and_data['ouput'],s=200)
```

```python
or_data
```

```python
xor_data
```

```python
sns.scatterplot(x=xor_data['input1'],y=xor_data['input2'],hue=xor_data['ouput'],s=200)
```

```python
from sklearn.linear_model import Perceptron
clf1=Perceptron()
clf2=Perceptron()
clf3=Perceptron()
```

```python
clf1.fit(and_data.iloc[:,0:2].values,and_data.iloc[:,-1].values)
clf2.fit(or_data.iloc[:,0:2].values,or_data.iloc[:,-1].values)
clf3.fit(xor_data.iloc[:,0:2].values,xor_data.iloc[:,-1].values)
```

```python
clf1.coef_
```

```python
clf1.intercept_
```

```python
x=np.linspace(-1,1,5)
y=-x+1
```

```python
plt.plot(x,y)
sns.scatterplot(x=and_data['input1'],y=and_data['input2'],hue=and_data['ouput'],s=200)
```

```python
clf2.coef_
```

```python
clf2.intercept_
```

```python
x1=np.linspace(-1,1,5)
y1=-x+0.5
```

```python
plt.plot(x1,y1)
sns.scatterplot(x=or_data['input1'],y=or_data['input2'],hue=or_data['ouput'],s=200)
```

```python
clf3.coef_
```

```python
clf3.intercept_
```

```python
from mlxtend.plotting import plot_decision_regions
```

```python
plot_decision_regions(xor_data.iloc[:,0:2].values,xor_data.iloc[:,-1].values, clf=clf3, legend=2)
```
