Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python
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
Container 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
Tom Rink
python
Commits
99573c54
Commit
99573c54
authored
10 months ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
d9cad14a
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
modules/machine_learning/classification.py
+17
-10
17 additions, 10 deletions
modules/machine_learning/classification.py
with
17 additions
and
10 deletions
modules/machine_learning/classification.py
+
17
−
10
View file @
99573c54
...
...
@@ -15,8 +15,14 @@ import sklearn.tree as tree
from
sklearn.tree
import
export_graphviz
# The independent variables (features) we want to use:
# params = ['cld_temp_acha', 'supercooled_cloud_fraction', 'cld_reff_dcomp', 'cld_opd_dcomp', 'cld_cwp_dcomp']
params
=
[
'
cld_temp_acha
'
,
'
supercooled_cloud_fraction
'
,
'
cld_reff_dcomp
'
,
'
cld_opd_dcomp
'
]
# feature_params = ['cld_temp_acha', 'supercooled_cloud_fraction', 'cld_reff_dcomp', 'cld_opd_dcomp', 'cld_cwp_dcomp']
# feature_params = ['cld_temp_acha', 'supercooled_cloud_fraction', 'cld_reff_dcomp', 'cld_opd_dcomp']
feature_params
=
[
'
cld_temp_acha
'
,
'
supercooled_cloud_fraction
'
,
'
cld_reff_acha
'
,
'
cld_opd_acha
'
]
# The dependent variable (target)
target_param
=
'
icing_intensity
'
params
=
feature_params
+
[
target_param
]
def
metrics
(
y_true
,
y_pred
,
y_pred_prob
=
None
):
...
...
@@ -74,15 +80,16 @@ def plot_confusion_matrix(cm, classes,
def
get_feature_target_data
(
csv_file
,
reduce_frac
=
1.0
,
random_state
=
42
,
standardize
=
True
,
remove_nan
=
False
):
icing_df
=
pd
.
read_csv
(
csv_file
)
icing_df
=
icing_df
[
params
]
# Random selection of reduce_frac of the rows
icing_df
=
icing_df
.
sample
(
axis
=
0
,
frac
=
reduce_frac
,
random_state
=
random_state
)
# Remove these, more than half seem to be NaN
icing_df
=
icing_df
.
drop
(
'
lwc_dcomp
'
,
axis
=
1
)
icing_df
=
icing_df
.
drop
(
'
iwc_dcomp
'
,
axis
=
1
)
# Remove this column for now.
icing_df
=
icing_df
.
drop
(
'
cld_geo_thick
'
,
axis
=
1
)
# # Remove these, more than half seem to be NaN
# icing_df = icing_df.drop('lwc_dcomp', axis=1)
# icing_df = icing_df.drop('iwc_dcomp', axis=1)
# # Remove this column for now.
# icing_df = icing_df.drop('cld_geo_thick', axis=1)
print
(
'
num obs, features:
'
,
icing_df
.
shape
)
if
remove_nan
:
...
...
@@ -91,7 +98,7 @@ def get_feature_target_data(csv_file, reduce_frac=1.0, random_state=42, standard
# icing_df = icing_df[icing_df.cld_temp_acha < 273.10]
x
=
np
.
asarray
(
icing_df
[
params
])
x
=
np
.
asarray
(
icing_df
[
feature_
params
])
if
standardize
:
stdSclr
=
preprocessing
.
StandardScaler
()
stdSclr
.
fit
(
x
)
...
...
@@ -100,7 +107,7 @@ def get_feature_target_data(csv_file, reduce_frac=1.0, random_state=42, standard
joblib
.
dump
(
stdSclr
,
'
/Users/tomrink/stdSclr_4.pkl
'
)
# The dependent variable (target) --------------------------------------------
y
=
np
.
asarray
(
icing_df
[
'
icing_intensity
'
])
y
=
np
.
asarray
(
icing_df
[
target_param
])
y
=
np
.
where
(
y
==
-
1
,
0
,
y
)
y
=
np
.
where
(
y
>=
1
,
1
,
y
)
...
...
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