Financial Model Taiwan
Financial Model Taiwan is a Python package designed to preprocess, train, and predict financial models. It includes functionalities for data ingestion, preprocessing, resampling, model training, evaluation, and optimization. This package aims to provide a comprehensive solution for financial modeling with support for various machine learning algorithms and techniques.
Model Architecture
The following image illustrates the model architecture:
Workflow Overview
-
Data Ingestion:
- Load data from CSV files.
- Split data into training and testing sets.
-
Preprocessing Pipeline:
- Define preprocessing steps.
- Handle missing values.
- Standardize/normalize data.
- Select important features.
-
Resampling:
- Perform data resampling to handle class imbalance.
-
Initial Model Training:
- Train multiple models: Random Forest, Logistic Regression, SVM, Gradient Boosting, XGBoost, KSBBoost, ANN.
- Evaluate models based on performance metrics.
- Select the best performing models for stacking.
-
Optimizing Model for Performance:
- Stack the best models (XGBoost and Random Forest).
- Optimize hyperparameters using Optuna.
- Tune the stacked model.
- Adjust thresholds to minimize type I and type II errors.
- Increase recall and finalize the model.
Installation
You can install the package via pip:
pip install financial_model_taiwan
Usage
Training a New Model
from financial_model_taiwan.Orchestrator import FinModel
pipeline = FinModel(data_path='data/train_data.csv', target_column='target')
pipeline.data_ingestion()
pipeline.data_preprocessing()
pipeline.data_resampling()
pipeline.train_model()
pipeline.save_model('models/trained_model.bin')
evaluation_results = pipeline.evaluate_model()
print(evaluation_results)
Using a Pre-trained Model
from financial_model_taiwan.Orchestrator import FinModel
pipeline = FinModel(data_path='data/train_data.csv', target_column='target', model_path='models/trained_model.bin')
pipeline.data_ingestion()
pipeline.data_preprocessing()
pipeline.load_model()
evaluation_results = pipeline.evaluate_model()
print(evaluation_results)
FinModel Class Attributes
data_path: Path to the CSV file containing the dataset.target_column: The target column name for prediction.model_path: Path to the pre-trained model file (optional).pipeline: The preprocessing pipeline.trainer: The model trainer.X_train: Training features.X_test: Testing features.y_train: Training labels.y_test: Testing labels.X_train_transformed: Transformed training features after preprocessing.X_test_transformed: Transformed testing features after preprocessing.X_resampled: Resampled training features to handle class imbalance.y_resampled: Resampled training labels to handle class imbalance.
Example Workflow
from financial_model_taiwan.Orchestrator import FinModel
pipeline = FinModel(data_path='../data/data.csv', model_path='../models/trained_model.bin', target_column='Bankrupt?')
pipeline.data_ingestion()
pipeline.data_preprocessing()
pipeline.data_resampling()
pipeline.train_model()
pipeline.save_model('trained_model_new.bin')
pipeline.load_model()
evaluation_results = pipeline.evaluate_model()
print(evaluation_results)
# Accessing Attributes
print(pipeline.X)
print(pipeline.y)
print(pipeline.X_test_transformed)
print(pipeline.X_train_transformed)
print(pipeline.X_resampled)
print(pipeline.y_resampled)
To check the predicted values
Although we didn't explicitly create a method we can call it using
pipeline.trainer.stacked_model.predict(pipeline.X_test_transformed)
Metadata
Release files for financial-model-taiwan 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| financial_model_taiwan-1.0.3.tar.gz | 3.3 MB | Without provenance | Details for financial_model_taiwan-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| financial_model_taiwan-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for financial_model_taiwan-1.0.3-py3-none-any.whl |
Total release size: 3.3 MB
Release files / financial_model_taiwan-1.0.3.tar.gz
| Download URL | financial_model_taiwan-1.0.3.tar.gz |
|---|---|
| Size | 3.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97da16603cfd244ea01155502c8b9c3dcfe250816fd3327a23205da724e74f93
|
|
BLAKE2b-256 checksum How to use checksums |
0c2095ea7ae9b170e1100e5c26cdcfabd0d38d7022c431366c87e3bec48d4919
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / financial_model_taiwan-1.0.3-py3-none-any.whl
| Download URL | financial_model_taiwan-1.0.3-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b28a73e0a6b750aa9a91b6efae284a719c1beb5276201b7cbe1823db843c744c
|
|
BLAKE2b-256 checksum How to use checksums |
9c40b0914563406e8f46b5e518ec3bb8b13dad760b3a61a9fa31806772a3466e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Security for financial-model-taiwan 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.