具体代码如下:
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
import random
np.set_printoptions(suppress=True)#不要科学计数法
seed = 2020
np.random.seed(seed) # Numpy module.
random.seed(seed) # Python random module.
plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
plt.close('all')
#定义Sigmoid
def sigmoid(x):
x=np.array(x,dtype=np.float64)
return 1/(1+np.exp(-x))
#求导
def d_sigmoid(x):
return x*(1-x)
def preprocess(data):
#将非数映射数字
#print(data)
for title in data.columns:
if data[title].dtype=='object':
encoder = LabelEncoder()
data[title] = encoder.fit_transform(data[title])
#print(data)
#去均值和方差归一化
ss = StandardSc