Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Hypo
SZU_CSSE_master
提交
4049f4a5
S
SZU_CSSE_master
项目概览
Hypo
/
SZU_CSSE_master
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SZU_CSSE_master
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4049f4a5
编写于
12月 04, 2019
作者:
H
hypox64
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
0.14142
上级
d9aef5a2
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
1486 addition
and
11 deletion
+1486
-11
dataloader.py
dataloader.py
+6
-0
evaluation.py
evaluation.py
+1
-1
result/0.03246_0.14142.csv
result/0.03246_0.14142.csv
+1460
-0
train.py
train.py
+19
-10
未找到文件。
dataloader.py
浏览文件 @
4049f4a5
import
os
import
os
import
csv
import
csv
import
numpy
as
np
import
numpy
as
np
import
random
# import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
# load description_txt
# load description_txt
...
@@ -40,6 +41,11 @@ for i in range(len(colon_indexs)-1):
...
@@ -40,6 +41,11 @@ for i in range(len(colon_indexs)-1):
descriptions
.
append
(
mapping
)
descriptions
.
append
(
mapping
)
# print(descriptions)
# print(descriptions)
def
match_random
(
a
,
b
):
state
=
np
.
random
.
get_state
()
np
.
random
.
shuffle
(
a
)
np
.
random
.
set_state
(
state
)
np
.
random
.
shuffle
(
b
)
def
normlize
(
npdata
,
justprice
=
False
):
def
normlize
(
npdata
,
justprice
=
False
):
_min
=
np
.
min
(
npdata
)
_min
=
np
.
min
(
npdata
)
...
...
evaluation.py
浏览文件 @
4049f4a5
...
@@ -28,7 +28,7 @@ def RMSE(records_real,records_predict):
...
@@ -28,7 +28,7 @@ def RMSE(records_real,records_predict):
return
None
return
None
def
main
():
def
main
():
my_price
=
load_submission
(
'./
result/0.04145_0.15960
.csv'
)
my_price
=
load_submission
(
'./
datasets/sample_submission
.csv'
)
print
(
eval_test
(
my_price
))
print
(
eval_test
(
my_price
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
\ No newline at end of file
result/0.03246_0.14142.csv
0 → 100644
浏览文件 @
4049f4a5
此差异已折叠。
点击以展开。
train.py
浏览文件 @
4049f4a5
...
@@ -4,22 +4,24 @@ import dataloader
...
@@ -4,22 +4,24 @@ import dataloader
import
model
import
model
import
evaluation
import
evaluation
from
torch
import
nn
,
optim
from
torch
import
nn
,
optim
import
time
#parameter
#parameter
LR
=
0.0001
LR
=
0.0001
EPOCHS
=
100
EPOCHS
=
100
0
BATCHSIZE
=
1
BATCHSIZE
=
64
CONTINUE
=
False
CONTINUE
=
False
use_gpu
=
True
use_gpu
=
True
SAVE_FRE
=
5
SAVE_FRE
=
5
#train 0:1200 dev 1200:1460 test 1460: 2919
#load data
#load data
train_desc
,
train_price
,
test_desc
=
dataloader
.
load_all
()
train_desc
,
train_price
,
test_desc
=
dataloader
.
load_all
()
train_desc
.
tolist
()
train_price
.
tolist
()
#def network
#def network
net
=
model
.
Linear
(
79
,
1024
,
1
)
net
=
model
.
Linear
(
79
,
256
,
1
)
print
(
net
)
print
(
net
)
if
CONTINUE
:
if
CONTINUE
:
...
@@ -32,13 +34,16 @@ if use_gpu:
...
@@ -32,13 +34,16 @@ if use_gpu:
optimizer
=
torch
.
optim
.
Adam
(
net
.
parameters
(),
lr
=
LR
)
optimizer
=
torch
.
optim
.
Adam
(
net
.
parameters
(),
lr
=
LR
)
criterion
=
nn
.
MSELoss
()
criterion
=
nn
.
MSELoss
()
test_loss_list
=
[]
for
epoch
in
range
(
EPOCHS
):
for
epoch
in
range
(
EPOCHS
):
print
(
'Epoch {}/{}.'
.
format
(
epoch
+
1
,
EPOCHS
))
print
(
'Epoch {}/{}.'
.
format
(
epoch
+
1
,
EPOCHS
))
t1
=
time
.
time
()
net
.
train
()
net
.
train
()
price_pres
=
[]
price_pres
=
[]
price_trues
=
[]
price_trues
=
[]
dataloader
.
match_random
(
train_desc
,
train_price
)
for
i
in
range
(
int
(
len
(
train_desc
)
/
BATCHSIZE
)):
for
i
in
range
(
int
(
len
(
train_desc
)
/
BATCHSIZE
)):
desc
=
np
.
zeros
((
BATCHSIZE
,
79
),
dtype
=
np
.
float32
)
desc
=
np
.
zeros
((
BATCHSIZE
,
79
),
dtype
=
np
.
float32
)
price
=
np
.
zeros
((
BATCHSIZE
,
1
),
dtype
=
np
.
float32
)
price
=
np
.
zeros
((
BATCHSIZE
,
1
),
dtype
=
np
.
float32
)
...
@@ -61,8 +66,6 @@ for epoch in range(EPOCHS):
...
@@ -61,8 +66,6 @@ for epoch in range(EPOCHS):
price_pres
.
append
(
dataloader
.
convert2price
(
price_pre
.
cpu
().
detach
().
numpy
()[
j
][
0
]))
price_pres
.
append
(
dataloader
.
convert2price
(
price_pre
.
cpu
().
detach
().
numpy
()[
j
][
0
]))
train_loss
=
evaluation
.
RMSE
(
price_trues
,
price_pres
)
train_loss
=
evaluation
.
RMSE
(
price_trues
,
price_pres
)
net
.
eval
()
net
.
eval
()
price_pres
=
[]
price_pres
=
[]
for
i
in
range
(
len
(
test_desc
)):
for
i
in
range
(
len
(
test_desc
)):
...
@@ -72,8 +75,14 @@ for epoch in range(EPOCHS):
...
@@ -72,8 +75,14 @@ for epoch in range(EPOCHS):
price_pres
.
append
(
dataloader
.
convert2price
(
price_pre
.
cpu
().
detach
().
numpy
()[
0
][
0
]))
price_pres
.
append
(
dataloader
.
convert2price
(
price_pre
.
cpu
().
detach
().
numpy
()[
0
][
0
]))
test_loss
=
evaluation
.
eval_test
(
price_pres
)
test_loss
=
evaluation
.
eval_test
(
price_pres
)
test_loss_list
.
append
(
test_loss
)
dataloader
.
write_csv
(
price_pres
,
'./result/result_epoch'
+
str
(
epoch
+
1
)
+
'.csv'
)
dataloader
.
write_csv
(
price_pres
,
'./result_epoch'
+
str
(
epoch
+
1
)
+
'.csv'
)
t2
=
time
.
time
()
print
(
'--- Epoch train_loss:'
,
'%.6f'
%
train_loss
,
' test_loss:'
,
'%.6f'
%
test_loss
,
' cost time:'
,
'%.3f'
%
(
t2
-
t1
),
's'
)
t1
=
time
.
time
()
print
(
'--- Epoch train_loss:'
,
train_loss
,
' test_loss:'
,
test_loss
)
min_loss
=
min
(
test_loss_list
)
index_epoch
=
test_loss_list
.
index
(
min_loss
)
print
(
'
\n
min_loss:'
,
min_loss
,
'epoch:'
,
index_epoch
+
1
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录