Skip to main content

Kernel Ridge Regression Optimized by INFO Algorithm

Project description

INFO-Optimized Kernel Ridge Regression (KRidge)

This code implements a Kernel Ridge Regression (KRidge) model optimized using the INFO (Weighted Mean of Vectors Optimization) algorithm. The provided implementation focuses on predicting a target variable from a dataset and evaluating its performance using various metrics.

Features

  • KRidge Regression: A powerful non-linear regression technique using kernel functions to capture complex relationships in data.
  • INFO Optimization: Employs the INFO algorithm to determine optimal hyperparameters for the KRidge model, enhancing its predictive accuracy.
  • Performance Evaluation: Calculates and saves a comprehensive set of regression metrics (R2, RMSE, MAPE, KGE, NSE, WHD, VSD, WAI) to assess model performance on training and testing datasets.
  • Excel Output: Saves the calculated metrics and actual vs. predicted values into a well-structured Excel file for easy analysis and comparison.

Requirements

  • Python 3.x
  • Libraries: pandas, scikit-learn, openpyxl (install using pip install pandas scikit-learn openpyxl)
  • Metrics.py: A separate Python file containing the Save_Metrics function (provided in previous responses).
  • Run_INFO.py: A separate Python file containing the RUN_INFO and PredictedValue_TrainTest functions.

Usage

  1. Data Preparation:

    • Ensure your dataset is in an Excel file (e.g., 'Data.xlsx').
    • The last column of the dataset should contain the target variable you want to predict.
  2. Configuration:

    • nTs: Specifies the percentage of data to be used for testing (e.g., 0.3 for 30%).
    • kernel_type: Defines the kernel function to be used in KRidge (e.g., 'wavelet', 'rbf', etc.).
    • nP: The number of particles for the INFO optimization algorithm.
    • MaxIt: The maximum number of iterations for the INFO algorithm.
    • UC: Upper bound for the KRidge regularization parameter (C).
    • UKF: Upper bound for the KRidge kernel function coefficient.
  3. Running the Code:

    • Execute the Python script.
    • The optimized KRidge model will be trained, and results will be saved to 'Results of KRidge.xlsx'.

Output

The code will generate an Excel file named 'Results of KRidge.xlsx' containing the following sheets:

  • Metrics: Summarizes the calculated regression metrics for both training and testing sets.
  • Train_Predictions: Shows the actual target values (y_train) and the corresponding model predictions (y_train_pred) for the training dataset.
  • **Test_Predict

Install

  • pip install KRidge_INFO
  • pip install IM_Metrics
  • pip install info_optimizer


Eample:

import pandas as pd
from sklearn.model_selection import train_test_split
from IM_Metrics import Save_Metrics from KRidge_INFO.KRidge_INFO import RUN_INFO,PredictedValue_TrainTest

Read data

data = pd.read_excel('Data.xlsx')

nTs = 0.3 # Percentage of test dataset
X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=nTs, random_state=0)

kernel_type = 'wavelet'
nP = 50 MaxIt = 20 UC = 2e10 #Upper Bound for C coefficient in KRidge model UKF = 2e10 #Upper Bound for kernel function coefficient in KRidge model

best_parameters = RUN_INFO(nP, MaxIt,X_train, X_test, y_train, y_test,kernel_type,UC,UKF)

After obtaining final predictions

y_train_pred, y_train,y_test_pred,y_test = PredictedValue_TrainTest(best_parameters, kernel_type, X_train, y_train,X_test, y_test)

metrics_filename = 'Results of KRidge.xlsx' Save_Metrics(y_train, y_train_pred, y_test, y_test_pred,metrics_filename)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kridge_info-2.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

KRidge_INFO-2.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file kridge_info-2.1.0.tar.gz.

File metadata

  • Download URL: kridge_info-2.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.7

File hashes

Hashes for kridge_info-2.1.0.tar.gz
Algorithm Hash digest
SHA256 5dbfdccdd6328259e2495491e3f7ba6f9cf4be6a9ed4ab0488a69144898b199d
MD5 a67201e3714e0464f33cea53fe2d30ae
BLAKE2b-256 6cc7cd96489b02f4bd9d2936f40a1b05a9fbb3be545f13df3c32450a54642809

See more details on using hashes here.

File details

Details for the file KRidge_INFO-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: KRidge_INFO-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.7

File hashes

Hashes for KRidge_INFO-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ff170d6e8eb8a176dddc5a546c47d995987e455cc2134f7c00ce6a19c654564
MD5 5a683ece0d5afe081825251f80919ee9
BLAKE2b-256 fd1d347e04d60f3f2527d2edc20a3f09d0455759ffce58e7babe950a670bc1c0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page