probnet.models package¶
probnet.models.base_net module¶
- class probnet.models.base_net.BaseNet(sigma=1.0, kernel='gaussian', dist='euclidean', **kwargs)[source]¶
Bases:
BaseEstimatorBase class for neural network models. Inherits from BaseEstimator to integrate with scikit-learn pipelines.
- SUPPORTED_CLS_METRICS¶
Dictionary of supported classification metrics.
- Type:
dict
- SUPPORTED_REG_METRICS¶
Dictionary of supported regression metrics.
- Type:
dict
- CLS_OBJ_LOSSES¶
Dictionary of classification objective losses.
- Type:
dict
- SUPPORTED_KERNELS¶
List of supported kernel functions.
- Type:
list
- SUPPORTED_METRICS¶
List of supported distance metrics.
- Type:
list
- Parameters:
sigma (float, default=1.0) – The bandwidth parameter for the kernel function.
kernel (str, default='gaussian') – The kernel function to use.
dist (str, default='euclidean') – The distance metric to use.
kwargs (dict) – Additional keyword arguments for customization.
- CLS_OBJ_LOSSES = {}¶
- SUPPORTED_CLS_METRICS = {'AS': 'max', 'BSL': 'min', 'CEL': 'min', 'CKS': 'max', 'F1S': 'max', 'F2S': 'max', 'FBS': 'max', 'GINI': 'min', 'GMS': 'max', 'HL': 'min', 'HS': 'max', 'JSI': 'max', 'KLDL': 'min', 'LS': 'max', 'MCC': 'max', 'NPV': 'max', 'PS': 'max', 'ROC-AUC': 'max', 'RS': 'max', 'SS': 'max'}¶
- SUPPORTED_KERNELS = ['gaussian', 'laplace', 'cauchy', 'epanechnikov', 'uniform', 'triangular', 'quartic', 'cosine', 'logistic', 'sigmoid', 'multiquadric', 'inverse_multiquadric', 'rational_quadratic', 'exponential', 'power', 'linear', 'bessel', 'vonmises', 'vonmises_fisher']¶
- SUPPORTED_METRICS = ['euclidean', 'manhattan', 'chebyshev', 'minkowski', 'hamming', 'canberra', 'braycurtis', 'jaccard', 'sokalmichener', 'sokalsneath', 'russellrao', 'yule', 'kulsinski', 'rogers_tanimoto', 'kulczynski', 'morisita', 'morisita_horn', 'dice', 'kappa', 'rogers', 'jensen', 'jensen_shannon', 'hellinger', 'bhattacharyya', 'cityblock', 'cosin', 'correlation', 'mahalanobis']¶
- SUPPORTED_REG_METRICS = {'A10': 'max', 'A20': 'max', 'A30': 'max', 'ACOD': 'max', 'APCC': 'max', 'AR': 'max', 'AR2': 'max', 'CI': 'max', 'COD': 'max', 'COR': 'max', 'COV': 'max', 'CRM': 'min', 'DRV': 'min', 'EC': 'max', 'EVS': 'max', 'GINI': 'min', 'GINI_WIKI': 'min', 'JSD': 'min', 'KGE': 'max', 'MAAPE': 'min', 'MAE': 'min', 'MAPE': 'min', 'MASE': 'min', 'ME': 'min', 'MRB': 'min', 'MRE': 'min', 'MSE': 'min', 'MSLE': 'min', 'MedAE': 'min', 'NNSE': 'max', 'NRMSE': 'min', 'NSE': 'max', 'OI': 'max', 'PCC': 'max', 'PCD': 'max', 'R': 'max', 'R2': 'max', 'R2S': 'max', 'RAE': 'min', 'RMSE': 'min', 'RSE': 'min', 'RSQ': 'max', 'SMAPE': 'min', 'VAF': 'max', 'WI': 'max'}¶
- evaluate(y_true, y_pred, list_metrics=None)[source]¶
Return the list of performance metrics of the prediction.
- fit(X, y)[source]¶
Fit the model to the training data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data.
y (array-like of shape (n_samples,)) – Target values.
- static load_model(load_path='history', filename='model.pkl')[source]¶
- Parameters:
load_path (str, optional) – Directory path where the model file is located. Defaults to “history”.
filename (str) – Name of the file to be loaded. If the filename doesn’t end with “.pkl”, the extension is automatically added.
- Returns:
The model loaded from the specified pickle file.
- Return type:
object
- predict(X)[source]¶
Predict target values for the given input data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input data.
- Returns:
Predicted target values.
- Return type:
array-like
- predict_proba(X)[source]¶
Predict class probabilities for the given input data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input data.
- Returns:
Predicted class probabilities.
- Return type:
array-like
- save_metrics(y_true, y_pred, list_metrics=('RMSE', 'MAE'), save_path='history', filename='metrics.csv')[source]¶
Save evaluation metrics to csv file
- Parameters:
y_true (ground truth data) –
y_pred (predicted output) –
list_metrics (list of evaluation metrics) –
save_path (saved path (relative path, consider from current executed script path)) –
filename (name of the file, needs to have ".csv" extension) –
- save_model(save_path='history', filename='model.pkl')[source]¶
Save model to pickle file
- Parameters:
save_path (saved path (relative path, consider from current executed script path)) –
filename (name of the file, needs to have ".pkl" extension) –
- save_y_predicted(X, y_true, save_path='history', filename='y_predicted.csv')[source]¶
Save the predicted results to csv file
- Parameters:
X (The features data, nd.ndarray) –
y_true (The ground truth data) –
save_path (saved path (relative path, consider from current executed script path)) –
filename (name of the file, needs to have ".csv" extension) –
probnet.models.grnn module¶
- class probnet.models.grnn.GrnnRegressor(sigma=1.0, kernel='gaussian', dist='euclidean', k_neighbors=None, normalize_output=True, **kwargs)[source]¶
Bases:
BaseNet,RegressorMixinGeneral Regression Neural Network (GRNN) implementation.
- sigma¶
The bandwidth parameter for the kernel function.
- Type:
float
- kernel¶
The kernel function to use (‘gaussian’, ‘laplace’, ‘epanechnikov’,…).
- Type:
str
- dist¶
The distance method to use (‘euclidean’, ‘manhattan’, ‘cosine’,…).
- Type:
str
- k_neighbors¶
The number of nearest neighbors to consider. If None, all training samples are used.
- Type:
int or None
- normalize_output¶
Whether to normalize the output predictions.
- Type:
bool
- kwargs¶
Additional keyword arguments for customization.
- Type:
dict
- SUPPORTED_KERNELS = ['gaussian', 'laplace', 'cauchy', 'epanechnikov']¶
- SUPPORTED_METRICS = ['euclidean', 'manhattan']¶
- evaluate(y_true, y_pred, list_metrics=('MSE', 'MAE'))[source]¶
Return the list of performance metrics of the prediction.
- Parameters:
y_true (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted values for X.
list_metrics (list) – You can get metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns:
results – The results of the list metrics
- Return type:
dict
- fit(X, y)[source]¶
Fit the GRNN model to the training data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data.
y (array-like of shape (n_samples,)) – Target values.
- Returns:
self – The fitted model.
- Return type:
- predict(X)[source]¶
Predict target values for the given input data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input data.
- Returns:
predictions – Predicted target values.
- Return type:
array-like of shape (n_samples,)
- score(X, y)[source]¶
Return the real R2 (Coefficient of Determination) method, not (Pearson’s Correlation Index)^2 like Scikit-Learn library.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
- Returns:
result – The result of selected method
- Return type:
float
- scores(X, y, list_metrics=('MSE', 'MAE'))[source]¶
Return the list of regression metrics of the prediction.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
list_metrics (list, default=("MSE", "MAE")) – You can get regression metrics from Permetrics library: https://permetrics.readthedocs.io/en/latest/pages/regression.html
- Returns:
results – The results of the list metrics
- Return type:
dict
probnet.models.pnn module¶
- class probnet.models.pnn.PnnClassifier(sigma=1.0, kernel='gaussian', dist='euclidean', normalize_output=True, class_prior=None, sample_weights=None, **kwargs)[source]¶
Bases:
BaseNet,ClassifierMixinProbabilistic Neural Network (PNN) Classifier implementation.
- sigma¶
The bandwidth parameter for the kernel function.
- Type:
float
- kernel¶
The kernel function to use (‘gaussian’, ‘laplace’, ‘cauchy’, ‘epanechnikov’,…).
- Type:
str
- dist¶
The distance method to use (‘euclidean’, ‘manhattan’,…).
- Type:
str
- normalize_output¶
Whether to normalize the output probabilities.
- Type:
bool
- class_prior¶
Prior probabilities of the classes. If None, uniform priors are used.
- Type:
array-like or None
- sample_weights¶
Weights for the training samples. If None, all samples are weighted equally.
- Type:
array-like or None
- kwargs¶
Additional keyword arguments for customization.
- Type:
dict
- SUPPORTED_KERNELS = ['gaussian', 'laplace', 'cauchy', 'epanechnikov']¶
- SUPPORTED_METRICS = ['euclidean', 'manhattan']¶
- evaluate(y_true, y_pred, list_metrics=('AS', 'RS'))[source]¶
Return the list of classification performance metrics of the prediction.
- Parameters:
y_true (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted values for X.
list_metrics (list) – You can get classification metrics from Permetrics library: https://permetrics.readthedocs.io/en/latest/pages/classification.html
- Returns:
results – The results of the list metrics
- Return type:
dict
- fit(X, y)[source]¶
Fit the PNN model to the training data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data.
y (array-like of shape (n_samples,)) – Target values.
- Returns:
self – The fitted model.
- Return type:
- predict(X)[source]¶
Predict class labels for the given input data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input data.
- Returns:
predictions – Predicted class labels.
- Return type:
array-like of shape (n_samples,)
- predict_proba(X)[source]¶
Predict class probabilities for the given input data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Input data.
- Returns:
probabilities – Predicted class probabilities.
- Return type:
array-like of shape (n_samples, n_classes)
- score(X, y)[source]¶
Return the real Accuracy Score metric
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
- Returns:
result – The result of selected metric
- Return type:
float
- scores(X, y, list_metrics=('AS', 'RS'))[source]¶
Return the list of classification metrics of the prediction.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
list_metrics (list, default=("AS", "RS")) – You can get classification metrics from Permetrics library: https://permetrics.readthedocs.io/en/latest/pages/classification.html
- Returns:
results – The results of the list metrics
- Return type:
dict