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

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:

主站蜘蛛池模板: 辉南县| 宁都县| 龙南县| 凌源市| 赞皇县| 哈尔滨市| 康马县| 宣威市| 女性| 彰化市| 志丹县| 托克托县| 合作市| 湖州市| 中超| 咸宁市| 磐石市| 龙州县| 文水县| 龙州县| 桃园县| 浦县| 金昌市| 方山县| 葵青区| 抚松县| 隆化县| 田阳县| 江安县| 毕节市| 郓城县| 平舆县| 胶南市| 惠安县| 清徐县| 泽普县| 江孜县| 河南省| 梨树县| 余庆县| 进贤县|