Skip to content

mtyszler/LivingIncomeModel

Repository files navigation

LIVING INCOME Model: a machine learning approach towards Living Income predictions

License: CC BY-SA 4.0

[Last update 17/12/2020]

notebooks re-run on 24/10/2022 (except TPOT) to update heroku build matching python 3.10.8 and updated dependencies

In this repo I use previous data from a larger project to develop a Machine Learning model to predict if farmers reach the living income benchmark value, using only 9 indicators.

This is a continuation of the work presented in Living Income Analysis. The work is advanced in two ways:

  1. The model is simplified to use only 9 variables, which makes it very accesible (applied) researchers and decision makers
  2. The model is made directly available in a web app

The web app is inspired by the web app develop for the project https://github.com/mtyszler/Disaster-Response-Project

Key files

The key files in this repo are:

Exploratory Notebooks:

Machine Learning model

The model can be downloaded here.

To use it in python:

import joblib
import numpy as np
import pandas as pd

model = joblib.load("LI_simplified_model.pkl")

## create X, with these columns:
# Estimated income percentage from sale of cocoa  (between 0-1)
# Cocoa production (kg/ha) (= Cocoa production (kg) / Productive land under cocoa (ha) )
# Cocoa production (kg)   
# Productive land under cocoa (ha)    
# Cocoa land owned (ha)   
# Hectares with trees between 5 and 25 years old  
# Estimated income percentage from own small business or trading  (between 0-1)
# Head: age 
# Estimated income percentage from sale of other crops  (between 0-1)  
# Land used to cultivate all crops (ha) 

classification_label = model.predict(X)
classification_prob = model.predict_proba(X)[:,1]*100

Web app:

The web app has 4 pages:

Home (= landing page)

This page has form to input 9 farming household characteristics. After clicking Calculate chance the app returns the prediction and probability of achieving the living income benchmark.

This is the main use of the app.

About the dataset

This page has some basic info about the training and testing datasets, as well as graphs about the all the features. It contains a bar chart showing how many observations reach the living income benchmark in the training and testing sets, as well as histograms of all the 9 features, compared between those achieving and not achieving the living income benchmark in the training and testing sets.

ML model performance

This page has some info about the performance of the ML model. It shows a few metrics as well as a confusion table.

Download the model

In this page the user can download the model for own use in python. It contains basic script explaining how to use the model.

Local use

To run the web app locally:

python app/run.py then go to http://0.0.0.0:3001/ or localhost:3001

  • Alternatevely, in unix system type: gunicorn app.run:app -b 0.0.0.0:3001 to run a local gunicorn server

Live Demo

A live version of the app can be see at https://living-income-model.herokuapp.com/

Web app Requirements

This projects uses Python 3.10.8 and was developed in windows 10 system. Python package requirements for the web app can be found in requirements.txt.

Because the project is deployed at Heroku, build-22.

Write-ups:

There are 3 write-ups related to this project:

  • An initial non-technical blog post about the findings of the initial analysis can be found at Medium
  • A follow-up non-technical blog post about the findings of the this analysis and web app can be found at Medium
  • A technical write-up about this project can be found at Medium

Author

Marcelo Tyszler

www.marcelotyszler.com

image image

License

License: CC BY-SA 4.0

This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages