Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
20200503_GFZ
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ML_Telegrafenberg
hackathons
20200503_GFZ
Merge requests
!2
Adds code/notebooks from Mark Rudolf
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Adds code/notebooks from Mark Rudolf
group1_add_mark
into
master
Overview
0
Commits
1
Pipelines
0
Changes
3
Merged
Graeme Weatherill
requested to merge
group1_add_mark
into
master
4 years ago
Overview
0
Commits
1
Pipelines
0
Changes
3
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
9d846b4f
1 commit,
4 years ago
3 files
+
3672
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
group1/Conv_example.py
0 → 100644
+
102
−
0
Options
import
pandas
as
pd
import
numpy
as
np
from
sklearn.preprocessing
import
normalize
from
keras.models
import
Sequential
from
keras.layers
import
Dense
,
Dropout
,
Conv1D
,
Flatten
,
MaxPooling1D
from
keras
import
optimizers
from
keras
import
backend
as
K
from
sklearn.model_selection
import
train_test_split
import
sklearn
from
sklearn.metrics
import
mean_squared_error
from
sklearn.preprocessing
import
MinMaxScaler
import
os
import
sys
df
=
pd
.
read_csv
(
"
LUCAS.csv
"
,
header
=
0
)
#XN = df[df.columns[6:]].values
#XD = (XN[:,4:np.shape(XN)[1]-1]-XN[:,5:np.shape(XN)[1]])/2
#X3 = X2[:,np.random.choice(np.arange(np.shape(XN)[1]),10)]
input_data
=
df
[
df
.
columns
[
4
:]].
values
output_data
=
df
[[
"
SOC
"
]].
values
#out_data = df[df.columns[4:6]].values
#input_data = XD
from
sklearn.model_selection
import
train_test_split
input_data
=
np
.
expand_dims
(
input_data
,
axis
=
2
)
input_train
,
input_test
,
output_train
,
output_test
=
train_test_split
(
input_data
,
output_data
,
test_size
=
0.33
,
random_state
=
42
)
input_shape
=
np
.
shape
(
input_train
)
#idx = np.random.permutation(np.shape(input_data)[0])
#ida = idx[:int(0.5*len(input_data))]
#idb = idx[int(0.5*len(input_data)):]
#input_train = input_data[ida]
#input_test = input_data[idb]
#output_train = out_data[ida]
#output_test = out_data[idb]
def
coeff_determination
(
y_true
,
y_pred
):
from
keras
import
backend
as
K
SS_res
=
K
.
sum
(
K
.
square
(
y_true
-
y_pred
))
SS_tot
=
K
.
sum
(
K
.
square
(
y_true
-
K
.
mean
(
y_true
)
)
)
return
(
1
-
SS_res
/
(
SS_tot
+
K
.
epsilon
())
)
#Build keras NN model
K
.
clear_session
()
model
=
Sequential
()
model
.
add
(
Conv1D
(
filters
=
64
,
kernel_size
=
27
,
activation
=
'
relu
'
,
input_shape
=
(
1000
,
1
)))
model
.
add
(
Conv1D
(
filters
=
64
,
kernel_size
=
3
,
activation
=
'
relu
'
))
model
.
add
(
Dropout
(
0.5
))
model
.
add
(
MaxPooling1D
(
pool_size
=
2
))
model
.
add
(
Flatten
())
model
.
add
(
Dense
(
100
,
activation
=
'
relu
'
))
model
.
add
(
Dense
(
1
,
activation
=
"
relu
"
))
##model.add(Conv1D(64,2, activation="relu", input_dim=len(input_train[0])))
#model.add(Conv1D(filters=64, kernel_size=27, activation='relu', input_shape = (1000,1)))
##model.add(Dense(8, activation="softmax"))
#model.add(Dropout(0.5))
#model.add(MaxPooling1D(pool_size=2))
#model.add(Flatten())
#model.add(Dense(64, activation="relu"))
#model.add(Dense(1, activation="relu"))
model
.
compile
(
optimizer
=
"
RMSprop
"
,
loss
=
"
mean_squared_error
"
,
metrics
=
[
coeff_determination
])
model
.
fit
(
input_train
,
output_train
,
epochs
=
200
,
batch_size
=
32
)
calculated_cal
=
model
.
predict
(
input_train
)
calculated_val
=
model
.
predict
(
input_test
)
rmse_train
=
np
.
sqrt
(
mean_squared_error
(
output_train
,
calculated_cal
))
rmse_val
=
np
.
sqrt
(
mean_squared_error
(
output_test
,
calculated_val
))
R2_train
=
sklearn
.
metrics
.
r2_score
(
output_train
,
calculated_cal
)
R2_val
=
sklearn
.
metrics
.
r2_score
(
output_test
,
calculated_val
)
print
(
rmse_train
)
print
(
rmse_val
)
print
(
R2_train
)
print
(
R2_val
)
\ No newline at end of file
Loading