Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
project
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OST
ML
Virtual Quality Control for Injection Molding
project
Compare revisions
59d83d93171525607329d45595668f9f827cd0d5 to 7ac5afbddead94693174a5b36cd719fb6f7c64e8
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
ost/ml/virtual-quality-control-for-injection-molding/project
Select target project
No results found
7ac5afbddead94693174a5b36cd719fb6f7c64e8
Select Git revision
Swap
Target
ost/ml/virtual-quality-control-for-injection-molding/project
Select target project
ost/ml/virtual-quality-control-for-injection-molding/project
1 result
59d83d93171525607329d45595668f9f827cd0d5
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (3)
add model evaluation
· 138d5fd4
Andri Joos
authored
6 months ago
138d5fd4
fix ci pipeline
· 88b77ecd
Andri Joos
authored
6 months ago
88b77ecd
Merge branch 'model_evaluation'
· 7ac5afbd
Andri Joos
authored
6 months ago
7ac5afbd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+15
-2
15 additions, 2 deletions
.gitlab-ci.yml
.vscode/launch.json
+23
-0
23 additions, 0 deletions
.vscode/launch.json
pyproject.toml
+1
-0
1 addition, 0 deletions
pyproject.toml
src/app.py
+38
-3
38 additions, 3 deletions
src/app.py
with
77 additions
and
5 deletions
.gitlab-ci.yml
View file @
7ac5afbd
...
...
@@ -3,9 +3,9 @@ stages:
.run_script
:
stage
:
run_scripts
image
:
python:3-
alpine
image
:
python:3-
bookworm
tags
:
-
amd64
# needed for matplotlib
-
amd64
# needed for matplotlib
& scikit-learn
variables
:
PIP_ROOT_USER_ACTION
:
ignore
before_script
:
...
...
@@ -47,3 +47,16 @@ multi_feature_regression_manual_features:
script
:
-
vqcfim multi-feature-regression --train-data dataset/InjectionMolding_Train.csv --out out --target 'mass'
--features Inj1PosVolAct_Var Inj1PrsAct_meanOfInjPhase ClpFceAct_1stPCscore
model_evaluation
:
extends
:
.run_script
needs
:
-
job
:
multi_feature_regression_p_value
artifacts
:
true
artifacts
:
expire_in
:
1d
paths
:
-
out/
script
:
-
vqcfim model-evaluation --model out/multi_feature_regression_model.pickle --test-data dataset/InjectionMolding_Test.csv --target mass --out out
--features Inj1PosVolAct_Var Inj1PrsAct_meanOfInjPhase Inj1HtgEd3Act_1stPCscore ClpFceAct_1stPCscore
This diff is collapsed.
Click to expand it.
.vscode/launch.json
View file @
7ac5afbd
...
...
@@ -75,6 +75,29 @@
"Inj1PrsAct_meanOfInjPhase"
,
"ClpFceAct_1stPCscore"
]
},
{
"name"
:
"Python Debugger: Model Evaluation"
,
"type"
:
"debugpy"
,
"request"
:
"launch"
,
"program"
:
"${workspaceFolder}/src/app.py"
,
"console"
:
"integratedTerminal"
,
"args"
:
[
"model-evaluation"
,
"-m"
,
"out/multi_feature_regression_model.pickle"
,
"--test-data"
,
"dataset/InjectionMolding_Test.csv"
,
"--target"
,
"mass"
,
"-o"
,
"out"
,
"-f"
,
"Inj1PosVolAct_Var"
,
"Inj1PrsAct_meanOfInjPhase"
,
"Inj1HtgEd3Act_1stPCscore"
,
"ClpFceAct_1stPCscore"
]
}
]
}
This diff is collapsed.
Click to expand it.
pyproject.toml
View file @
7ac5afbd
...
...
@@ -7,6 +7,7 @@ dependencies = [
"seaborn >= 0.13.2, < 1.0.0"
,
"matplotlib >= 3.9.2, < 4.0.0"
,
"statsmodels >= 0.14.4, < 1.0.0"
,
"scikit-learn >= 1.5.2, < 2.0.0"
,
]
maintainers
=
[
{name
=
"Andri Joos"
}
,
...
...
This diff is collapsed.
Click to expand it.
src/app.py
View file @
7ac5afbd
...
...
@@ -6,6 +6,7 @@ import matplotlib.pyplot as plt
import
math
from
typing
import
List
,
Tuple
import
statsmodels.api
as
sm
from
sklearn.metrics
import
mean_squared_error
# is not deprecated, only squared param
TRAIN_DATA_ARG
=
'
--train-data
'
TRAIN_DATA_ARG_SHORT
=
'
-t
'
...
...
@@ -20,6 +21,9 @@ P_VALUE_THRESHOLD_ARG = '--p-value-threshold'
DEFAULT_P_VALUE_THRESHOLD
=
0.05
FEATURES_ARG
=
'
--features
'
FEATURES_ARG_SHORT
=
'
-f
'
MODEL_ARG
=
'
--model
'
MODEL_ARG_SHORT
=
'
-m
'
TEST_DATA_ARG
=
'
--test-data
'
PVALUE_COLUMN_NAME
=
'
p-value
'
RSQUARED_COLUMN_NAME
=
'
R^2
'
...
...
@@ -40,7 +44,7 @@ def get_possible_features_from_p_value(data: pd.DataFrame, target: str, p_value_
return
possible_features
.
where
(
possible_features
[
PVALUE_COLUMN_NAME
]
<
p_value_threshold
).
dropna
()
def
multi_feature_regression_model
(
train_data
:
pd
.
DataFrame
,
selected_features
:
List
[
str
]
|
None
,
p_value_threshold
:
float
|
None
,
target
:
str
)
->
sm
.
OLS
:
def
multi_feature_regression_model
(
train_data
:
pd
.
DataFrame
,
selected_features
:
List
[
str
]
|
None
,
p_value_threshold
:
float
|
None
,
target
:
str
)
->
Tuple
[
sm
.
OLS
,
List
[
str
]]
:
features
:
List
[
str
]
=
None
if
selected_features
is
not
None
and
p_value_threshold
is
None
:
features
=
selected_features
...
...
@@ -149,14 +153,37 @@ R^2: {best_feature[RSQUARED_COLUMN_NAME]}
def
multi_feature_regression
(
train_data_file
:
Path
,
target
:
str
,
selected_features
:
List
[
str
]
|
None
,
p_value_threshold
:
float
|
None
,
out_dir
:
Path
):
train_data
=
pd
.
read_csv
(
train_data_file
)
y
=
train_data
[
target
]
model
,
features
=
multi_feature_regression_model
(
train_data
,
selected_features
,
p_value_threshold
,
target
)
print
(
model
.
summary
())
ensure_directory
(
out_dir
)
multi_feature_regression_results_file
=
out_dir
/
'
multi_feature_regression_results.txt
'
multi_feature_regression_results_file
=
out_dir
/
'
multi_feature_regression_
train_
results.txt
'
with
open
(
multi_feature_regression_results_file
,
'
w
'
)
as
f
:
f
.
write
(
f
'''
features:
{
features
}
rsquared:
{
model
.
rsquared
}
rsquared:
{
model
.
rsquared
}
,
train_MSE:
{
mean_squared_error
(
y
,
model
.
fittedvalues
)
}
'''
)
ensure_directory
(
out_dir
)
model_file
=
out_dir
/
'
multi_feature_regression_model.pickle
'
model
.
save
(
model_file
)
def
model_evaluation
(
model_file
:
Path
,
test_data_file
:
Path
,
features
:
List
[
str
],
target
:
str
,
out_dir
:
Path
):
test_data
=
pd
.
read_csv
(
test_data_file
)
model
:
sm
.
OLS
=
sm
.
load
(
model_file
)
X_test
=
sm
.
add_constant
(
test_data
[
features
])
y_test
=
test_data
[
target
]
y_pred
=
model
.
predict
(
X_test
)
test_mse
=
mean_squared_error
(
y_test
,
y_pred
)
print
(
f
'
Test MSE:
{
test_mse
}
'
)
ensure_directory
(
out_dir
)
model_evaluation_file
=
out_dir
/
'
model_evaluation.txt
'
with
open
(
model_evaluation_file
,
'
w
'
)
as
f
:
f
.
write
(
f
'''
test_MSE:
{
test_mse
}
'''
)
def
main
():
...
...
@@ -185,6 +212,14 @@ def main():
multi_feature_regression_features_group
.
add_argument
(
P_VALUE_THRESHOLD_ARG
,
action
=
'
store
'
,
type
=
float
,
required
=
False
,
default
=
None
)
multi_feature_regression_subparser
.
set_defaults
(
func
=
lambda
train_data
,
target
,
out
,
features
,
p_value_threshold
,
func
:
multi_feature_regression
(
train_data
,
target
,
features
,
p_value_threshold
,
out
))
model_evaluation_subparser
=
subparsers
.
add_parser
(
'
model-evaluation
'
,
aliases
=
[
'
me
'
],
description
=
'
Evaluates a model
'
)
model_evaluation_subparser
.
add_argument
(
MODEL_ARG
,
MODEL_ARG_SHORT
,
action
=
'
store
'
,
type
=
Path
,
required
=
True
)
model_evaluation_subparser
.
add_argument
(
TEST_DATA_ARG
,
action
=
'
store
'
,
type
=
Path
,
required
=
True
)
model_evaluation_subparser
.
add_argument
(
TARGET_ARG
,
action
=
'
store
'
,
type
=
str
,
required
=
True
)
model_evaluation_subparser
.
add_argument
(
OUT_DIR_ARG
,
OUT_DIR_ARG_SHORT
,
action
=
'
store
'
,
type
=
Path
,
required
=
False
,
default
=
DEFAULT_OUT_DIR
)
model_evaluation_subparser
.
add_argument
(
FEATURES_ARG
,
FEATURES_ARG_SHORT
,
action
=
'
store
'
,
type
=
str
,
required
=
True
,
nargs
=
'
+
'
)
model_evaluation_subparser
.
set_defaults
(
func
=
lambda
model
,
test_data
,
target
,
out
,
features
,
func
:
model_evaluation
(
model
,
test_data
,
features
,
target
,
out
))
parsed_args
=
argument_parser
.
parse_args
()
args
=
vars
(
parsed_args
)
parsed_args
.
func
(
**
args
)
...
...
This diff is collapsed.
Click to expand it.