Metadata-Version: 2.4
Name: SAFEPG
Version: 1.0.0
Summary: The frequency-severity model has been widely adopted to analyze highly right-skewed data 
Home-page: https://github.com/YikaiZhang95/SAFE
Author: Yikai Zhang
Author-email: yikai-zhang@uiowa.edu
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy==1.25.2
Requires-Dist: pandas==1.5.2
Requires-Dist: pytest==8.3.4
Requires-Dist: scikit-learn==1.1.3
Requires-Dist: scipy==1.9.3
Requires-Dist: seaborn==0.12.1
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: summary

# SAFEPG
![img](https://release-badges-generator.vercel.app/api/releases.svg?user=YikaiZhang95&repo=SAFE&gradient=0000ff,8bd1fa)

A Novel SAFE Model for Predicting Climate-Related Extreme Losses

## Table of contents

* [Introduction](#introduction)
* [Installation](#installation)
* [Quick start](#quick-start)
* [Usage](#usage)
* [Getting help](#getting-help)

## Introduction

The frequency-severity model has been widely adopted to analyze highly right-skewed data 
in actuarial science. To make the model more interpretable, we expect a predictor has 
the same direction of impact on both the frequency and severity. However, the 
compotemporary use of the frequence-severity model typically yields inconsistent signs. 
To this end, we propose a novel sign-aligned regularization term to facilitate the sign 
consistency between the components in the frequency-severity model to enhance interpretability. 
We also demonstrate our design of the penalty leads to an algorithm which is quite efficient 
in analyzing large-scale data and its superior performance with both simulation and real examples.


## Installation

You can use `pip` to install this package.

```sh
pip install SAFEPG
```


## Quick start

The usages are similar with `scikit-learn`:

```python
model = SafeModel()
model.fit(x=x, y=y, k=k, lambda_=ulam)
```

## Usage

### Generate simulation data
`SAFEPG` provides a simulation data generation function to test functions in the library:

```python
from SAFEPG.SAFEPG import SafeModel
import numpy as np
from scipy.stats import poisson, gamma

np.random.seed(0)
n = 100
p = 5
x = np.random.randn(n, p)
beta_true = np.full(5, 0.1)
gamma_true = np.array([1, 1, 1, -1, -1])

mu = x @ beta_true
k = poisson.rvs(mu=np.exp(mu))
alpha_val = 1
theta = np.exp(x @ gamma_true) / alpha_val
y = gamma.rvs(a=alpha_val, scale=theta)

lambda_val = [1.0]
ind_p = np.array([1, 1, 1, 0, 0])

model = SafeModel()
model.fit(x=x, y=y, k=k, lambda_=lambda_val, ind_p = ind_p)
```

## Getting help
Any questions or suggestions please contact: <yikai-zhang@uiowa.edu>

