Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Fidle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Talks
Fidle
Commits
06416cff
Commit
06416cff
authored
1 year ago
by
Achille Mbogol Touye
Browse files
Options
Downloads
Patches
Plain Diff
help function
parent
f13cacf3
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
WineQuality-DNN_Reg-lightning/data_load.py
+67
-0
67 additions, 0 deletions
WineQuality-DNN_Reg-lightning/data_load.py
with
67 additions
and
0 deletions
WineQuality-DNN_Reg-lightning/data_load.py
0 → 100644
+
67
−
0
View file @
06416cff
import
torch
import
pandas
as
pd
import
lightning.pytorch
as
pl
class
WineQualityDataset
(
pl
.
LightningDataModule
):
"""
Wine Quality dataset.
"""
def
__init__
(
self
,
csv_file
,
transform
=
None
):
"""
Args:
csv_file (string): Path to the csv file.
transform (callable, optional): Optional transform to be applied on a sample.
"""
super
().
__init__
()
self
.
csv_file
=
csv_file
self
.
data
=
pd
.
read_csv
(
self
.
csv_file
,
header
=
0
,
sep
=
'
;
'
)
self
.
transform
=
transform
def
__len__
(
self
):
return
len
(
self
.
data
)
def
__getitem__
(
self
,
idx
):
features
=
self
.
data
.
iloc
[
idx
,
:
-
1
].
values
.
astype
(
'
float32
'
)
target
=
self
.
data
.
iloc
[
idx
,
-
1
:].
values
.
astype
(
'
float32
'
)
sample
=
{
'
features
'
:
features
,
'
quality
'
:
target
}
if
self
.
transform
:
sample
=
self
.
transform
(
sample
)
return
sample
class
Normalize
(
WineQualityDataset
):
"""
normalize data
"""
def
__init__
(
self
,
csv_file
):
mean
,
std
=
self
.
compute_mean_and_std
(
csv_file
)
self
.
mean
=
mean
self
.
std
=
std
def
compute_mean_and_std
(
self
,
csv_file
):
"""
Compute the mean and std for each feature.
"""
dataset
=
WineQualityDataset
(
csv_file
)
mean
=
dataset
.
data
.
iloc
[:,:
-
1
].
mean
(
axis
=
0
).
values
.
astype
(
'
float32
'
)
std
=
dataset
.
data
.
iloc
[:,:
-
1
].
std
(
axis
=
0
).
values
.
astype
(
'
float32
'
)
return
mean
,
std
def
__call__
(
self
,
sample
):
features
,
target
=
sample
[
'
features
'
],
sample
[
'
quality
'
]
norm_features
=
(
features
-
self
.
mean
)
/
self
.
std
# normalize features
return
{
'
features
'
:
norm_features
,
'
quality
'
:
target
}
class
ToTensor
(
object
):
"""
Convert ndarrays in sample to Tensors.
"""
def
__call__
(
self
,
sample
):
features
,
target
=
sample
[
'
features
'
],
sample
[
'
quality
'
]
return
{
'
features
'
:
torch
.
from_numpy
(
features
),
'
quality
'
:
torch
.
from_numpy
(
target
)
}
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