API
Index
Functions
Maxnet.complexity
— MethodGet the number of non-zero coefficients in the model
Maxnet.default_features
— Methoddefault_features(np)
Takes the number of presences np
and returns a Vector
of AbstractFeatureClass
s that are used my maxent as default.
If np
is less than ten, then only LinearFeature
and CategoricalFeature
are used. If it is at least 10, then QuadraticFeature
is additionally used. If it is at least 15, then HingeFeature
is additionally used. If it is at least 80, then ProductFeature
is additionally used.
Maxnet.maxnet
— Methodmaxnet(
p_a, X;
features, regularization_multiplier, regularization_function,
addsamplestobackground, weight_factor,
kw...
)
Fit a model using the maxnet algorithm.
Arguments
p_a
: ABitVector
where presences aretrue
and background samples arefalse
X
: A Tables.jl-compatible table of predictors. Categorical predictors should beCategoricalVector
s
Keywords
features
: Either aVector
ofAbstractFeatureClass
to be used in the model, or aString
where "l" = linear and categorical, "q" = quadratic, "p" = product, "t" = threshold, "h" = hinge (e.g. "lqh"); or By default, the features are based on the number of presences are used. Seedefault_features
regularization_multiplier
: A constant to adjust regularization, where a higherregularization_multiplier
results in a higher penalization for features and therefore less overfitting.regularization_function
: A function to compute a regularization for each feature. A defaultregularization_function
is built in and should be used in most cases.addsamplestobackground
: Whether to add presence values to the background. Defaults totrue
.n_knots
: the number of knots used for Threshold and Hinge features. Defaults to 50. Ignored if there are neither Threshold nor Hinge featuresweight_factor
: AFloat64
value to adjust the weight of the background samples. Defaults to 100.0.kw...
: Further arguments to be passed toGLMNet.glmnet
Returns
model
: A model of typeMaxnetModel
Examples
using Maxnet
p_a, env = Maxnet.bradypus();
bradypus_model = maxnet(p_a, env; features = "lq")
# Output
Fit Maxnet model
Features classes: Maxnet.AbstractFeatureClass[LinearFeature(), CategoricalFeature(), QuadraticFeature()]
Entropy: 6.114650341746531
Model complexity: 21
Variables selected: [:frs6190_ann, :h_dem, :pre6190_l1, :pre6190_l10, :pre6190_l4, :pre6190_l7, :tmn6190_ann, :vap6190_ann, :ecoreg, :cld6190_ann, :dtr6190_ann, :tmx6190_ann]
StatsAPI.predict
— Methodpredict(m, X; link, clamp)
Use a maxnet model to predict on new data.
Arguments
m
: a MaxnetModel as returned bymaxnet
X
: aTables.jl
-compatible table of predictors. All columns that were used to fitm
should be present inX
Keywords
link
: the link function used. Defaults to CloglogLink(), which is the default on the Maxent Java appliation since version 4.3. Alternatively, LogitLink() was the Maxent default on earlier versions. To get exponential output, which can be interpreted as predicted abundance, use LogLink() IdentityLink() returns the exponent without any transformation.clamp
: Iftrue
, values inx
will be clamped to the range the model was trained on. Defaults tofalse
.
Returns
A Vector
with the resulting predictions.
Example
using Maxnet
p_a, env = Maxnet.bradypus();
bradypus_model = maxnet(p_a, env; features = "lq")
prediction = predict(bradypus_model, env)
Types
Maxnet.MaxnetBinaryClassifier
— TypeMaxnetBinaryClassifier
A model type for constructing a Maxnet, based on Maxnet.jl, and implementing the MLJ model interface.
From MLJ, the type can be imported using
MaxnetBinaryClassifier = @load MaxnetBinaryClassifier pkg=Maxnet
Do model = MaxnetBinaryClassifier()
to construct an instance with default hyper-parameters. Provide keyword arguments to override hyper-parameter defaults, as in MaxnetBinaryClassifier(features=...)
.
Training data
In MLJ or MLJBase, bind an instance model
to data with
mach = machine(model, X, y)
where
X
: any table of input features (eg, aDataFrame
) whose columns each have one of the following element scitypes:Continuous
or<:Multiclass
. Checkscitypes
withschema(X)
.y
: is the target, which can be anyAbstractVector
whose element scitype is<:Binary
. The first class should refer to background values, and the second class to presence values.
Hyper-parameters
features
: Specifies which features classes to use in the model, e.g. "lqh" for linear, quadratic and hinge features. See also Maxnet.maxnetregularization_multiplier = 1.0
: 'Adjust how tight the model will fit. Increasing this will reduce overfitting.regularization_function
: A function to compute the regularization of each feature class. Defaults toMaxnet.default_regularization
addsamplestobackground = true
: Controls wether to add presence values to the background.n_knots = 50
: The number of knots used for Threshold and Hinge features. A higher number gives more flexibility for these features.weight_factor = 100.0
: AFloat64
value to adjust the weight of the background samples.link = Maxnet.CloglogLink()
: The link function to use when predicting. SeeMaxnet.predict
clamp = false
: Clamp values passed toMLJBase.predict
to the range the model was trained on.
Operations
predict(mach, Xnew)
: return predictions of the target given featuresXnew
having the same scitype asX
above. Predictions are probabilistic and can be interpreted as the probability of presence.
Fitted Parameters
The fields of fitted_params(mach)
are:
fitresult
: ATuple
where the first entry is theMaxnet.MaxnetModel
returned by the Maxnet algorithm and the second the entry is the classes ofy
Report
The fields of report(mach)
are:
selected_variables
: AVector
ofSymbols
of the variables that were selected.selected_features
: AVector
ofMaxnet.ModelMatrixColumn
with the features that were selected.complexity
: the number of selected features in the model.
Example
using MLJBase, Maxnet
p_a, env = Maxnet.bradypus()
y = coerce(p_a, Binary)
X = coerce(env, Count => Continuous)
mach = machine(MaxnetBinaryClassifier(features = "lqp"), X, y)
fit!(mach)
yhat = MLJBase.predict(mach, env)