Skip to content

Commit

Permalink
add pytorch
Browse files Browse the repository at this point in the history
  • Loading branch information
QLMX committed Aug 13, 2019
1 parent f24aa75 commit 2bd1b8e
Show file tree
Hide file tree
Showing 21 changed files with 613 additions and 323 deletions.
12 changes: 0 additions & 12 deletions .idea/data_mining_models.iml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

256 changes: 0 additions & 256 deletions .idea/workspace.xml

This file was deleted.

12 changes: 9 additions & 3 deletions README.md
Expand Up @@ -18,6 +18,10 @@
* [binary_class.py](./code/keras/binary_class.py):keras实现的mlp,做二分类任务
* [multi_class.py](./code/keras/multi_class.py):keras实现的mlp,做多分类任务
* [regression.py](./code/keras/regression.py):keras实现的mlp,做回归任务
* pytorch实现的mlp
* [binary_class.py](./code/pytorch/binary_class.py):pytorch实现的mlp,做二分类任务
* [multi_class.py](./code/pytorch/multi_class.py):pytorch实现的mlp,做多分类任务
* [regression.py](./code/pytorch/regression.py):实现的mlp,做回归任务

## 2.环境设置

Expand All @@ -30,6 +34,7 @@ matplotlib
sklearn
tensorflow==1.12.0
keras==2.2.4
pytorch
seaborn
lightgbm==2.2.1
xgboost==0.90
Expand All @@ -40,14 +45,15 @@ xgboost==0.90
* [基于lightgbm实现的二分类、多分类和回归任务](https://mp.weixin.qq.com/s/t6EpWmLWP81DcJ7AUro3Ng)
* [基于xgboost实现的二分类、多分类和回归任务]()
* [基于keras实现的二分类、多分类和回归任务]()
* [基于pytorch实现的二分类、多分类和回归任务]()

## 4. 最后

目前只整理了几个常用的模型,下一步会将用到的不错的代码同步进来,如果有什么问题可以直接指出来,大家一块进步,如果对您有帮助,麻烦点击一下star,鼓励一下作者。如果有最新内容更新会第一时间在微信公众号公布,希望能和大家一块成长
目前只整理了几个常用的模型,下一步会将用到的不错的代码同步进来,如果有问题或者发现有什么错误的地方需要交流可以通过微信公众号或者代码中的邮箱联系作者,也可以通过Issues提出问题。如果该项目对你有帮助,麻烦点击一下star鼓励一下作者。如果有最新内容更新会第一时间在微信公众号内发布,希望能和你一起在AI方面前进,成长

作者的知乎:[QLMX](https://www.zhihu.com/people/qlmx-61/activities)
作者的知乎:[QLMX](https://www.zhihu.com/people/qlmx-61/activities), 知乎专栏:[ML与DL成长之路](https://zhuanlan.zhihu.com/c_1138029910563020800)

微信公号:AI成长社![wx](./result/wx.jpg)
微信公号:AI成长社<img src="./result/wx.jpg" width = "80" height = "80" />



13 changes: 7 additions & 6 deletions code/keras/binary_class.py
Expand Up @@ -6,7 +6,7 @@
@contact: wenruichn@gmail.com
@time: 2019-08-02 10:26
公众号:AI成长社
知乎:https://www.zhihu.com/people/qlmx-61/activities
知乎:https://www.zhihu.com/people/qlmx-61/columns
"""
import pandas as pd
import numpy as np
Expand Down Expand Up @@ -42,7 +42,7 @@
train = data[data['label'] != -1]
test = data[data['label'] == -1]

#del dataframe
## Clean up the memory
del data, train_data, test_data
gc.collect()

Expand All @@ -61,8 +61,8 @@
for i in train_x.columns:
# print(i, train_x[i].isnull().sum(), test[i].isnull().sum())
if train_x[i].isnull().sum() != 0:
train_x[i] = train_x[i].fillna(0)
test[i] = test[i].fillna(0)
train_x[i] = train_x[i].fillna(-1)
test[i] = test[i].fillna(-1)

## normalized
scaler = StandardScaler()
Expand All @@ -71,7 +71,7 @@

## simple mlp model
K.clear_session()
def build_model(dropout_rate=0.25, activation='relu'):
def MLP(dropout_rate=0.25, activation='relu'):
start_neurons = 512
model = Sequential()
model.add(Dense(start_neurons, input_dim=train_X.shape[1], activation=activation))
Expand Down Expand Up @@ -128,7 +128,7 @@ def plot_loss_acc(history, fold):
x_valid, y_valid = train_X[val_], train_y[val_]


model = build_model(dropout_rate=0.5, activation='tanh')
model = MLP(dropout_rate=0.5, activation='tanh')
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
history = model.fit(x_train, y_train,
validation_data=[x_valid, y_valid],
Expand All @@ -148,3 +148,4 @@ def plot_loss_acc(history, fold):
result = []
for pred in NN_predictions:
result.append(1 if pred > threshold else 0)
print(result)

0 comments on commit 2bd1b8e

Please sign in to comment.