Skip to content

Commit

Permalink
Encapsulate Poisson regression parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dpkatz committed Jun 12, 2018
1 parent a51d433 commit 3facc11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/LightGBM/Internal/CommandLineWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ applicationPMap =
[ (P.Regression P.L1, "regression_l1")
, (P.Regression P.L2, "regression_l2")
, (P.Regression P.Huber, "huber")
, (P.Regression P.Poisson, "poisson")
, (P.Regression P.Quantile, "quantile")
, (P.Regression P.MAPE, "mape")
, (P.Regression P.Gamma, "gamma")
Expand All @@ -94,6 +93,9 @@ mkTweedieString (P.TweedieVariancePower p) = "tweedie_variance_power=" ++ show p
mkFairString :: P.FairRegressionParam -> String
mkFairString (P.FairC pd) = "fair_c=" ++ show (unrefine pd)

mkPoissonString :: P.PoissonRegressionParam -> String
mkPoissonString (P.PoissonMaxDeltaStep pd) = "poisson_max_delta_step=" ++ show (unrefine pd)

mkDartString :: P.DARTParam -> String
mkDartString (P.DropRate r) = "drop_rate=" ++ show (unrefine r)
mkDartString (P.SkipDrop r) = "skip_drop=" ++ show (unrefine r)
Expand All @@ -120,6 +122,8 @@ mkOptionString (P.Objective (P.Regression (P.Tweedie tparams))) =
["application=tweedie"] ++ map mkTweedieString tparams
mkOptionString (P.Objective (P.Regression (P.Fair fparams))) =
["application=fair"] ++ map mkFairString fparams
mkOptionString (P.Objective (P.Regression (P.Poisson pparams))) =
["application=poisson"] ++ map mkPoissonString pparams
mkOptionString (P.Objective a) = ["application=" ++ (applicationPMap M.! a)]
mkOptionString (P.BoostingType (P.DART dartParams)) =
["boosting=dart"] ++ map mkDartString dartParams
Expand Down Expand Up @@ -209,8 +213,6 @@ mkOptionString (P.ValidInitScoreFile f) =
mkOptionString (P.ForcedSplits f) = ["forced_splits=" ++ f]
mkOptionString (P.Sigmoid d) = ["sigmoid=" ++ show (unrefine d)]
mkOptionString (P.Alpha d) = ["alpha=" ++ show (unrefine d)]
mkOptionString (P.PoissonMaxDeltaStep d) =
["poisson_max_delta_step=" ++ show (unrefine d)]
mkOptionString (P.ScalePosWeight d) = ["scale_pos_weight=" ++ show d]
mkOptionString (P.BoostFromAverage b) = ["boost_from_average=" ++ show b]
mkOptionString (P.IsUnbalance b) = ["is_unbalance=" ++ show b]
Expand Down
14 changes: 10 additions & 4 deletions src/LightGBM/Parameters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module LightGBM.Parameters
, NumMachines
, ParallelismParams(..)
, ParallelismStyle(..)
, PoissonRegressionParam(..)
, RegressionApp(..)
, TweedieRegressionParam(..)
, VerbosityLevel(..)
Expand Down Expand Up @@ -120,7 +121,6 @@ data Param
| ForcedSplits FilePath
| Sigmoid PositiveDouble -- ^ Used in Binary classification and LambdaRank
| Alpha OpenProperFraction -- ^ Used in Huber loss and Quantile regression
| PoissonMaxDeltaStep PositiveDouble -- ^ Used in Poisson regression
| ScalePosWeight Double -- ^ Used in Binary classification
| BoostFromAverage Bool -- ^ Used only in RegressionL2 task
| IsUnbalance Bool -- ^ Used in Binary classification (set to true if training data are unbalanced)
Expand All @@ -132,12 +132,18 @@ data Param
| TrainingMetric Bool
deriving (Eq, Show)

-- | Parameters for Fair loss regression
--- | Parameters for Fair loss regression
data FairRegressionParam =
FairC PositiveDouble
deriving (Eq, Show, Generic)
deriving (Eq, Show, Generic)
instance Hashable FairRegressionParam

-- | Parameters for Poisson regression
data PoissonRegressionParam =
PoissonMaxDeltaStep PositiveDouble
deriving (Eq, Show, Generic)
instance Hashable PoissonRegressionParam

-- | Different types of Boosting approaches
data Booster
= GBDT -- ^ Gradient Boosting Decision Tree
Expand All @@ -158,7 +164,7 @@ data RegressionApp
| L2 -- ^ RMS errror metric
| Huber
| Fair [FairRegressionParam]
| Poisson
| Poisson [PoissonRegressionParam]
| Quantile
| MAPE
| Gamma
Expand Down

0 comments on commit 3facc11

Please sign in to comment.