-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjust bin values for text features in RFF #99
Changes from 1 commit
da5ba89
1d90e8f
3b6c45f
eea1cf2
b958887
a54131b
dae829d
d6ad74f
d9dee94
1bb28c6
441ab06
546fcfc
13cb288
c47e9bc
e8d616b
e133bb4
20a9c40
e39dad6
1c6d359
5e2857c
a2ffd3a
3c35a13
2f4f77a
6187e55
7ff99fe
bdc0608
dfc1a40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,12 @@ private[op] object FeatureDistribution { | |
|
||
val MaxBins = 100000 | ||
val AvgBinValue = 5000 | ||
val MaxTokenLowerLimit = 10 | ||
val getBins = (sum: Summary, bins: Int) => { | ||
// To catch categoricals | ||
if (sum.max < MaxTokenLowerLimit) bins | ||
else math.min(math.max(bins, sum.sum / AvgBinValue), MaxBins).intValue() | ||
} | ||
|
||
implicit val semigroup: Semigroup[FeatureDistribution] = new Semigroup[FeatureDistribution] { | ||
override def plus(l: FeatureDistribution, r: FeatureDistribution) = l.reduce(r) | ||
|
@@ -165,7 +171,7 @@ private[op] object FeatureDistribution { | |
bins: Int | ||
): FeatureDistribution = { | ||
val (nullCount, (summaryInfo, distribution)): (Int, (Array[Double], Array[Double])) = | ||
value.map(seq => 0 -> histValues(seq, summary, bins)) | ||
value.map(seq => 0 -> histValues(seq, summary, bins, getBins)) | ||
.getOrElse(1 -> (Array(summary.min, summary.max, summary.sum, summary.count) -> Array.fill(bins)(0.0))) | ||
|
||
FeatureDistribution( | ||
|
@@ -182,19 +188,19 @@ private[op] object FeatureDistribution { | |
* @param values values to bin | ||
* @param sum summary info for feature (max and min) | ||
* @param bins number of bins to produce | ||
* @param getBins | ||
* @return the bin information and the binned counts | ||
*/ | ||
// TODO avoid wrapping and unwrapping?? | ||
private def histValues( | ||
values: ProcessedSeq, | ||
sum: Summary, | ||
bins: Int | ||
bins: Int, | ||
getBins: (Summary, Int) => Int | ||
): (Array[Double], Array[Double]) = { | ||
values match { | ||
case Left(seq) => { | ||
val minBins = bins | ||
val maxBins = MaxBins | ||
val numBins = math.min(math.max(bins, sum.max / AvgBinValue), maxBins).intValue() | ||
val numBins = getBins(sum, bins) | ||
|
||
val hasher: HashingTF = new HashingTF(numFeatures = numBins) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have to create hasher every time or perhaps we can create it once? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the hashing dimension can be different for different features, the minimum number would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let see if we can reuse the hashing function without creating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and I think we can. See |
||
.setBinary(false) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add move this method to Summary class., ie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!