Hypsometric Relationship
Warning
This library is under development, none of the presented solutions are available for download.
Estimate the heights of the missing trees based on the heights measured in the field.
Class Parameters
HypRel(x, y, df, model, iterator)
Parameters | Description |
---|---|
x | The name of the column that contains the tree diameters/circumferences. |
y | The name of the column that contains the tree heights. |
df | The DataFrame containing the tree data. |
model | (Optional) A list of models used for estimating tree heights. If none, will use all models avaliable. |
iterator | (Optional) A column name string. Defines wich column will be used as a iterator. Could be a farm name, plot name, code or any unique identification tag. |
Class Functions
HypRel.run()
HypRel.metrics()
HypRel.plots(dir = None, show = None) #(1)
HypRel.get_coef()
- dir = The directory you want to save your plots!
If
dir == None
, then the plots will be displayed.
show = Display the plots on the screen! It can beTrue
orFalse
.
Parameters | Description |
---|---|
.run() | Fit the models |
.metrics() | Return a table of metrics of each evaluated model |
.plots(dir=None, show=True) | Return the height and residuals plots |
.get_coef() | Return the coefficients for each model |
Example Usage
hyp_rel_example.py | |
---|---|
1 2 |
|
- Import
HypRel
class. - Import
pandas
for data manipulation.
Create a variable for the HypRel Class
hyp_rel_example.py | |
---|---|
3 4 5 6 7 8 |
|
- Load your csv file.
- Create the variable
reg
containing the HypRel class. - Run the models and save in the
results
variable. - Run a evaluation for the fitted models and save on
metrics
variable. - Return the plots for the fitted models.
- Get the coefficients for each model fitted.
Available models
-
\[ \operatorname{Total height} =e^{(\beta_0+β1*\frac{1}{x})} \]
-
\[ \operatorname{Total height} = \beta_0 + \beta_1 * x + \beta_2 * x^2 \]
-
\[ \operatorname{Total height} = e^{(\beta_0+\beta_1*\ln(x))} \]
-
\[ \operatorname{Total height} = \beta_0 + \beta_1 * \ln(x) \]
-
\[ \operatorname{Total height} = (\frac{x^2}{\beta_0+\beta_1*x+\beta_2* x^2}) \]
-
\[ \operatorname{Total height} =(\frac{x^2}{\beta_0+\beta_1*x+\beta_2* x^2})+1.3 \]
- Explanation about ANN below.
Artificial Neural Network
When selecting the 'ann' model, 4 different structures of artificial neural networks will be tested. Only the result from 1 model will be returned. The model returned will be selected by the ranking function.
For the 'ann' model, the module sklearn.neural_network.MLPRegressor is used.
Ranking function
To select the best-performing models and rank them accordingly, the following metrics are obtained:
Métric name | Structure |
---|---|
Mean Absolute Error (MAE) | \( MAE = \frac{1}{n} \sum_{i=1}^{n} \|y_i - \hat{y}_i\| \) |
Mean Absolute Percentage Error (MAPE) | \( MAPE = \frac{100}{n} \sum_{i=1}^{n} \left\|\frac{y_i - \hat{y}_i}{y_i}\right\| \) |
Mean Squared Error (MSE) | \( MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 \) |
Root Mean Squared Error (RMSE) | \( RMSE = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2} \) |
R Squared (Coefficient of Determination) | \( R^2 = 1 - \frac{\sum_{i=1}^{n} (y_i - \hat{y}_i)^2}{\sum_{i=1}^{n} (y_i - \bar{y})^2} \) |
Explained Variance (EV) | \( EV = 1 - \frac{Var(y - \hat{y})}{Var(y)} \) |
Mean Error | \( Mean\ Error = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i) \) |
After obtaining the metric for each tested model, the values are normalized from 0 to 10. The worst model receives a score of 0, and the best model receives a score of 10.