数据集获取网址
SuperdataScience
神经元
输入信号:
X
1
,
X
2
,
.
.
.
X
m
X_1,X_2,...X_m
X1?,X2?,...Xm? 权重:
W
1
,
W
2
,
.
.
.
W
m
W_1,W_2,...W_m
W1?,W2?,...Wm?也是神经网络训练的对象 激活函数:
φ
φ
φ 隐藏神经元:
激活函数
读取神经元所有输入的和,再将其转化成输出
- 阈值函数
- sigmoid函数
- 线性整流函数ReLU(隐藏层常用)
- 双曲正切函数
神经网络如何训练
损失函数:实际值与预测值的欧式距离 正向传播:根据权重预测输出值 反向更新:根据损失函数调节每个权重
梯度下降
随机梯度下降
神经网络如何运作
正向传播
反向传播
实例
通过用户的特征辨别哪些客户可能会离开银行转投其他的银行
整体架构
import pandas as pd
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
from sklearn.compose import ColumnTransformer
dataset = pd.read_csv("F:\数模\美赛\Machine Learning A-Z Chinese Template Folder\Part 8 - Deep Learning\Section 32 - Artificial Neural Networks (ANN)\Churn_Modelling.csv")
x=dataset.iloc[:,3:13].values
y=dataset.iloc[:,13].values
labelencoder_x= LabelEncoder();
x[:,1]= labelencoder_x.fit_transform(x[:,1])
x[:,2]=labelencoder_x.fit_transform(x[:,2])
ct = ColumnTransformer([('one_hot_encoder', OneHotEncoder(), [1])], remainder='passthrough')
x = ct.fit_transform(x)
x=x[:,1:]
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=0)
from sklearn.preprocessing import StandardScaler
sc_x = StandardScaler()
x_train = sc_x.fit_transform(x_train)
x_test = sc_x.transform(x_test)
import keras
from keras.models import Sequential
from keras.layers import Dense
classifier=Sequential()
classifier.add(Dense(units=6,kernel_initializer='uniform',activation='relu',input_dim=11))
classifier.add(Dense(units=6,kernel_initializer='uniform',activation='relu'))
classifier.add(Dense(units=1,kernel_initializer='uniform',activation='sigmoid'))
classifier.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
classifier.fit(x_train,y_train,batch_size=5,epochs=100)
y_pred=classifier.predict(x_test)
y_pred=(y_pred>0.5)
from sklearn.metrics import confusion_matrix
cm=confusion_matrix(y_test,y_pred)
Tensorflow
开源的深度学习框架,由谷歌团队开发
Keras
建立在Tensorflow之上的框架
|