Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
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
Model registry
Operate
Environments
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
cs525-sp18-g07
spark
Commits
75f37573
Commit
75f37573
authored
11 years ago
by
Xinghao
Browse files
Options
Downloads
Patches
Plain Diff
Fix rounding error in LogisticRegression.scala
parent
c823ee1e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mllib/src/main/scala/spark/mllib/classification/LogisticRegression.scala
+4
-2
4 additions, 2 deletions
...scala/spark/mllib/classification/LogisticRegression.scala
with
4 additions
and
2 deletions
mllib/src/main/scala/spark/mllib/classification/LogisticRegression.scala
+
4
−
2
View file @
75f37573
...
...
@@ -21,6 +21,8 @@ import spark.{Logging, RDD, SparkContext}
import
spark.mllib.optimization._
import
spark.mllib.util.MLUtils
import
scala.math.round
import
org.jblas.DoubleMatrix
/**
...
...
@@ -42,14 +44,14 @@ class LogisticRegressionModel(
val
localIntercept
=
intercept
testData
.
map
{
x
=>
val
margin
=
new
DoubleMatrix
(
1
,
x
.
length
,
x
:_
*
).
mmul
(
localWeights
).
get
(
0
)
+
localIntercept
(
1.0
/
(
1.0
+
math
.
exp
(
margin
*
-
1
))).
toInt
round
(
1.0
/
(
1.0
+
math
.
exp
(
margin
*
-
1
))).
toInt
}
}
override
def
predict
(
testData
:
Array
[
Double
])
:
Int
=
{
val
dataMat
=
new
DoubleMatrix
(
1
,
testData
.
length
,
testData
:_
*
)
val
margin
=
dataMat
.
mmul
(
weightsMatrix
).
get
(
0
)
+
this
.
intercept
(
1.0
/
(
1.0
+
math
.
exp
(
margin
*
-
1
))).
toInt
round
(
1.0
/
(
1.0
+
math
.
exp
(
margin
*
-
1
))).
toInt
}
}
...
...
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