Skip to main content

This package helps the Data Scientist to train there model on dataset with different models without copy pasting the code again and again, this package is a Sklearn wrapper which does performs the model training. this saves time of developer and it also helps with detail metrics and for quick scan which model best fits for dataset

Project description

skwrapper

This package helps the Data Scientist to train there model on dataset with different models without copy pasting the code again and again, this package is a Sklearn wrapper which does performs the model training. this saves time of developer and it also helps with detail metrics and for quick scan which model best fits for dataset

Features

  • Supports regression and classifications models
  • Computes common regression and classificatons metrics.
  • Optional display of predicted values.
  • Easy-to-use unified interface for training and evaluation.

Installation

pip install skwrapper

Usage Example

## Import class from Library
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.read_csv("Social_Network_Ads.csv")

selected_row = df.loc[:, 'Age': 'Purchased']

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
# first we have to define X and y where X is the variable or feature input and y is the output target basically
x = selected_row[['Age', 'EstimatedSalary']]
y = selected_row['Purchased']

## Split the Data
X_train, x_test, Y_train, y_test = train_test_split( x, y, train_size=0.8, random_state=48 )

X_train.shape, x_test.shape


# doing standardization
scaler = StandardScaler()

#fit the scaler to the train set, it will learn the parameter
scaler.fit(X_train)  ## learn mean and std from the train dataset
X_train_scaled = scaler.transform(X_train)  ## Apply sacling
X_test_scaler = scaler.transform(x_test) ## Apply same scaling on X_test as well

#convert the numpy 2D arry to pd dataframes with column names on it as numpy array dont have column name after scaling
X_train_scaled_df = pd.DataFrame(X_train_scaled, columns=X_train.columns)  
X_test_scaler_df = pd.DataFrame(X_test_scaler, columns=x_test.columns) 

print(X_train_scaled_df.describe())
print(X_train.describe())


# Train and evaluate Models
|from skwrapper import sc, sr
## Single Model Execution for sc(Supervised Classification Models)
sc.perform(
    case=["logistic"],
    xy_train=[X_train_scaled_df, y_train],
    xy_test=[X_test_scaler_df, y_test],

    ## Optional Parameter
    show_pred=True # If True, predicted_values will be printed. If False, only evaluation metrics will be displayed.
)

## Multiple Model Execution for sc(Supervised Classification Models)
result = sc.perform(
    case=[" logistic", "svc", "knc"],
    xy_train=[X_train_scaled_df, y_train],
    xy_test=[X_test_scaler_df, y_test],

    ## Optional Parameter
    show_pred=True # If True, predicted_values will be printed. If False, only evaluation metrics will be displayed.
)

#----------------and for Supervised Regression Models-------------------#
## Single Model Execution:
sr.perform(
    case=["linearR"],
    xy_train=[X_train, y_train],
    xy_test=[X_test, y_test],

    #Optional Parameter
    show_pred=True # If True, predicted_values will be printed. If False, only evaluation metrics will be displayed.
)

## Multiple Model Execution:
sr.perform(
    case=["linearR", "svr", "knr"],
    xy_train=[X_train, y_train],
    xy_test=[X_test, y_test]
)

print(result) ## This will print all the metrics for all defiend models in **case**

# Access specific model metrics or predection value model object,
print("MSE for Linear Regression:", sc.metrics["linearR"]["mse"])
print("predicted_value for SVR:", sc.metrics["svr"]["predicted_value"])

##############
# dont do this
result = sc.perform( case=["logistic"], xy_train=[X_train_scaled_df, y_train], xy_test=[X_test_scaler_df, y_test],show_pred=True )
print("predicted_value for SVR:", result.metrics["svr"]["predicted_value"]) # result.metrics ❌
##############

## You Can Plot the predicted Values
sns.scatterplot(sc.metrics['svr']['predicted_value'])
plt.show()

Using Scikit-learn Parameters

This library acts as a wrapper around scikit-learn models, so you can pass model parameters exactly the same way you would in scikit-learn. All keyword arguments (**kwargs) are forwarded to the underlying scikit-learn model.

Example

from skwrapper import sc, sr
model = sr

model.perform(
    case=["rfr"],
    xy_train=(X_train, y_train),
    xy_test=(X_test, y_test),
    n_estimators=200,
    max_depth=10,
    random_state=42
)
- **Note: Model parameters must match the parameters of the corresponding scikit-learn estimator. Invalid parameters will raise an error.**

Supported Models

  • Wrapper class for multiple sklearn regression models.:
Model Description
linearR Linear Regression
ridge Ridge Regression
lasso Lasso Regression
svr Support Vector Regression
knr K-Nearest Neighbors Regressor
gbr Gradient Boosting Regressor
rfr Random Forest Regressor
dtr Decision Tree Regressor

Metrics

  • metrics computed automatically:
- Mean Squared Error (MSE)
- Mean Absolute Error (MAE)
- Root Mean Squared Error (RMSE)
- R² Score

  • Wrapper class for multiple sklearn Classifications models.:
Model Description
logistic Logistic Regression Classifier
svc Support Vector Classifier (SVC)
rfc Random Forest Classifier
gbc Gradient Boosting Classifier
knc K-Nearest Neighbors Classifier
dtc Decision Tree Classifier

Metrics

  • metrics computed automatically:
- accuracy
- confusion_matrix
- classification_report

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

skwrapper-0.1.5.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skwrapper-0.1.5-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file skwrapper-0.1.5.tar.gz.

File metadata

  • Download URL: skwrapper-0.1.5.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for skwrapper-0.1.5.tar.gz
Algorithm Hash digest
SHA256 14000a7f3dc0c85d403d5ad039366423e7b8dfcf845f195be6ac047879a0d747
MD5 50e763eee1e88b6fea619e6e2cf6f691
BLAKE2b-256 09eb493b8fb26484107872d88e7512476636254f1756b74f58aac714e37c52d5

See more details on using hashes here.

File details

Details for the file skwrapper-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: skwrapper-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for skwrapper-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2bf802c311f0f271c556558d5318598b88805502c302cfc1fe6d3ad43664fe55
MD5 c6ee259828fe8110fea36767ee1a225c
BLAKE2b-256 50408d4ca5ee53fa8b74893c2d6ee02481c4a920c5e9d6e1df8f99a6336bc59c

See more details on using hashes here.

Supported by

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