官术网_书友最值得收藏!

  • Hands-On Neural Networks
  • Leonardo De Marchi Laura Mitchell
  • 230字
  • 2021-06-24 14:00:16

The XOR problem

Let's try to solve the XOR problem we presented earlier with a simple FFNN, by performing the following steps:

  1. First of all, let's import everything we will need for this task and seed our random function:
import numpy as np
import pandas as pd
from sklearn.metrics import confusion_matrix
from sklearn.metrics import roc_auc_score
from sklearn.metrics import mean_squared_error
import matplotlib

matplotlib.use("TkAgg")

# initiating random number
np.random.seed(11)
  1. To make it more similar to a real-word problem, we will add some noise to the XOR input, and we will try to predict a binary task:
#### Creating the dataset

# mean and standard deviation for the x belonging to the first class
mu_x1, sigma_x1 = 0, 0.1

# Constant to make the second distribution different from the first
# x1_mu_diff, x2_mu_diff, x3_mu_diff, x4_mu_diff = 0.5, 0.5, 0.5, 0.5
x1_mu_diff, x2_mu_diff, x3_mu_diff, x4_mu_diff = 0, 1, 0, 1

# creating the first distribution
d1 = pd.DataFrame({'x1': np.random.normal(mu_x1, sigma_x1,
1000) + 0,
'x2': np.random.normal(mu_x1, sigma_x1,
1000) + 0,'type': 0})

d2 = pd.DataFrame({'x1': np.random.normal(mu_x1, sigma_x1,
1000) + 1,
'x2': np.random.normal(mu_x1, sigma_x1,
1000) - 0,'type': 1})

d3 = pd.DataFrame({'x1': np.random.normal(mu_x1, sigma_x1,
1000) - 0,
'x2': np.random.normal(mu_x1, sigma_x1,
1000) - 1,'type': 0})

d4 = pd.DataFrame({'x1': np.random.normal(mu_x1, sigma_x1,
1000) - 1,
'x2': np.random.normal(mu_x1, sigma_x1,
1000) + 1, 'type': 1})

data = pd.concat([d1, d2, d3, d4], ignore_index=True)

In this way, we will get a noisy XOR, as shown in the following screenshot:

主站蜘蛛池模板: 棋牌| 富平县| 兴仁县| 彭山县| 四平市| 贡山| 黄陵县| 合作市| 靖边县| 克什克腾旗| 乌审旗| 鄢陵县| 汪清县| 阿尔山市| 郴州市| 镇江市| 沾化县| 河津市| 中卫市| 温宿县| 南郑县| 江门市| 依兰县| 扎鲁特旗| 昌吉市| 元江| 平远县| 象山县| 广东省| 宝鸡市| 亳州市| 临潭县| 铅山县| 邯郸县| 抚顺市| 天长市| 怀远县| 原阳县| 陆河县| 海宁市| 米脂县|