Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
dream
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
dream
Commits
ee686e74
Commit
ee686e74
authored
Apr 15, 2014
by
panos
Committed by
Jérome Perrin
Jun 17, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a new function to replace the missing value with the meadian of the data set
parent
ee818b5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 deletion
+13
-1
dream/KnowledgeExtraction/ReplaceMissingValues.py
dream/KnowledgeExtraction/ReplaceMissingValues.py
+13
-1
No files found.
dream/KnowledgeExtraction/ReplaceMissingValues.py
View file @
ee686e74
...
@@ -22,9 +22,10 @@ Created on 19 Feb 2014
...
@@ -22,9 +22,10 @@ Created on 19 Feb 2014
@author: Panos
@author: Panos
'''
'''
from
StatisticalMeasures
import
BasicStatisticalMeasures
#The HandleMissingValues object
#The HandleMissingValues object
class
HandleMissingValues
:
class
HandleMissingValues
(
BasicStatisticalMeasures
)
:
#Three different approaches to handle missing values are included in this object
#Three different approaches to handle missing values are included in this object
def
ReplaceWithZero
(
self
,
mylist
):
#Replace in the given list the missing values with zero
def
ReplaceWithZero
(
self
,
mylist
):
#Replace in the given list the missing values with zero
i
=
0
i
=
0
...
@@ -53,3 +54,14 @@ class HandleMissingValues:
...
@@ -53,3 +54,14 @@ class HandleMissingValues:
mylist
[
i
]
=
mean
#For the values in the initial given list if there is a missing value replace it with the mean value of the new list
mylist
[
i
]
=
mean
#For the values in the initial given list if there is a missing value replace it with the mean value of the new list
i
+=
1
i
+=
1
return
mylist
#Return the given list, in which the missing values are replaced with the mean value
return
mylist
#Return the given list, in which the missing values are replaced with the mean value
def
ReplaceWithMedian
(
self
,
mylist
):
#Replace in the given list the missing values with the median value
list1
=
self
.
DeleteMissingValue
(
mylist
)
#Create a new list, which is the given list deleting the missing values (calling the DeleteMissingValue method)
A
=
BasicStatisticalMeasures
()
#Call the BasicStatisticalMeasures to calculate the median value
median
=
A
.
median
(
list1
)
#Calculate the median value of the new list
i
=
0
for
value
in
mylist
:
if
value
is
''
:
mylist
[
i
]
=
median
#For the values in the initial given list if there is a missing value replace it with the mean value of the new list
i
+=
1
return
mylist
#Return the given list, in which the missing values are replaced with the mean value
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment