Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOC-Mod
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
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
frilis
SOC-Mod
Commits
3332338f
Commit
3332338f
authored
2 years ago
by
frilis
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parent
3dd79422
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
loadin.py
+62
-0
62 additions, 0 deletions
loadin.py
with
62 additions
and
0 deletions
loadin.py
0 → 100644
+
62
−
0
View file @
3332338f
import
numpy
as
np
import
pandas
as
pd
from
sklearn.model_selection
import
train_test_split
from
sklearn.pipeline
import
make_pipeline
from
sklearn.ensemble
import
RandomForestRegressor
from
sklearn.preprocessing
import
StandardScaler
from
sklearn.metrics
import
mean_absolute_error
,
mean_squared_error
def
load_split
(
filepath
):
soc
=
pd
.
read_csv
(
filepath
,
header
=
0
)
X_soc
=
soc
[[
"
Catch
"
,
"
Conv
"
,
"
Elev
"
,
"
NDVI_median
"
]]
# MAKE THIS AS AN INPUT TO THE FUNCTION TO CHOOSE WHICH PARAMS WE TRAIN WITH
y_soc
=
soc
[
"
SOC (%)
"
]
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X_soc
,
y_soc
,
test_size
=
0.2
,
random_state
=
1
)
X_train
,
X_val
,
y_train
,
y_val
=
train_test_split
(
X_train
,
y_train
,
test_size
=
0.25
,
random_state
=
1
)
return
X_train
,
X_val
,
X_test
,
y_train
,
y_val
,
y_test
def
RFreg_test
(
X_train
,
X_test
,
y_train
,
y_test
):
pipeline
=
RandomForestRegressor
(
n_estimators
=
100
,
random_state
=
0
)
pipeline
.
fit
(
X_train
,
y_train
)
y_pred
=
pipeline
.
predict
(
X_test
)
print
(
"
Mean Squared Error is: %.2f
"
%
(
mean_squared_error
(
y_test
,
y_pred
)))
print
(
"
Mean Absolute Error is: %.2f
"
%
(
mean_absolute_error
(
y_test
,
y_pred
)))
print
(
""
)
return
0
def
main
():
# Initial test
"""
PART 1 - LOADING IN THE DATA
"""
# Load in the training, validation and test from dataset
X_tr
,
X_va
,
X_te
,
y_tr
,
y_va
,
y_te
=
load_split
(
'
Project/SOC_Database.csv
'
)
"""
PART 2 - CHOOSING FEATURES TO TRAIN ON
"""
# Make a section where we will be testing with various different parameters in the training set (variables)
# To obtain the optimal variables to train with
"""
PART 3 - VALIDATION TESTING TO FIND THE OPTIMAL PARAMETERS FOR EACH ALGORITHM
"""
# Make a section where we will be testing with the validation set and choosing the best parameters
# WRITE CODE
# STEPS FOR VALIDATION TESTING TO FIND OPTIMAL PARAMETERS:
# i) Choose 5 algorithms that we want to test (we can also do more!)
# ii) Identify the parameters for each algorithm that we need to optimize
# iii) Choose an evaluation method (rmse, mae, determination coefficient, F1-score, ratio of performance to deviation)
# iv) Estimate a logarithmic range of 10 values for each parameter and run loop testing combinations
# of those parameters with eachother and downselect the combo of parameters with smallest error
# v) Select for each algorithm the optimal parameters for the next section
"""
PART 4 - RUN TEST SET FOR EACH ALGORITHM WITH THE OPTIMAL PARAMETERS
"""
# Test algorithms again with the best parameters chosen from previous section to do a direct comparison
# Test each algorithm
RFreg_test
(
X_tr
,
X_te
,
y_tr
,
y_te
)
"""
PART 5 - TBD: IF ENOUGH TIME AT HAND: REPEAT TESTING IN A DIFFERENT DATASET AND COMPARE PERFORMANCE
"""
# This a test
# new
if
__name__
==
"
__main__
"
:
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment