gurulearn


Namegurulearn JSON
Version 1.0.18 PyPI version JSON
download
home_pageNone
Summarylibrary for MLModelAnalysis and multi image model(bug fix 2.0)
upload_time2024-10-26 17:41:21
maintainerNone
docs_urlNone
authorGuru Dharsan T
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ######                                                                      MLModelAnalysis                                                                 ###### #

MLModelAnalysis is a flexible, reusable class for training, evaluating, and making predictions with various machine learning regression models. This tool allows easy switching between models, consistent preprocessing, model evaluation, and prediction for a variety of machine learning tasks.

Supported Models
Linear Regression (linear_regression)
Decision Tree Regressor (decision_tree)
Random Forest Regressor (random_forest)
Support Vector Machine (svm)
Gradient Boosting Regressor (gradient_boosting)
K-Nearest Neighbors (knn)
AdaBoost Regressor (ada_boost)
Neural Network (MLP Regressor) (mlp)
XGBoost Regressor (xgboost)
Usage
1. Initializing the Model
Initialize the MLModelAnalysis class by specifying the model_type parameter, which defines the machine learning model you want to use. Below are examples of initializing with various models:

python
Copy code
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor, AdaBoostRegressor
from sklearn.svm import SVR
from sklearn.neighbors import KNeighborsRegressor
from sklearn.neural_network import MLPRegressor

# Initialize with Linear Regression
analysis = MLModelAnalysis(model_type='linear_regression')

# Initialize with Random Forest
analysis = MLModelAnalysis(model_type='random_forest')

# Initialize with XGBoost
analysis = MLModelAnalysis(model_type='xgboost')
2. Training and Evaluating the Model
The train_and_evaluate method preprocesses the data, trains the model, and displays evaluation metrics. Optionally, it saves the trained model, scaler, and encoders for later use.

Parameters:
csv_file: Path to the CSV file containing the dataset.
x_elements: List of feature columns.
y_element: Name of the target column.
model_save_path (Optional): Path to save the trained model, scaler, and encoders.
Example:
# Set the parameters
csv_file = 'data.csv'          # Path to the data file
x_elements = ['feature1', 'feature2']  # List of feature columns
y_element = 'target'            # Target column name

# Initialize the model
analysis = MLModelAnalysis(model_type='random_forest')

# Train and evaluate the model
analysis.train_and_evaluate(csv_file=csv_file, x_elements=x_elements, y_element=y_element, model_save_path='random_forest_model.pkl')
After running this code, the model will display R-squared and Mean Squared Error (MSE) metrics for both training and test sets. If model_save_path is specified, it saves the model for future predictions.

3. Loading the Model and Making Predictions
The load_model_and_predict method loads a saved model and makes predictions on new input data.

Parameters:
model_path: Path to the saved model file (created in the previous step).
input_data: Dictionary of feature names and values representing a single input instance for prediction.
Example:
# Define input data for prediction
input_data = {
    'feature1': 5.1,
    'feature2': 2.3
}

# Load the model and make a prediction
prediction = analysis.load_model_and_predict(model_path='random_forest_model.pkl', input_data=input_data)
print(f'Prediction: {prediction}')
4. Visualization
When using a linear_regression or svm model with only one feature, the train_and_evaluate method will automatically generate a Plotly plot of actual vs. predicted values for simple visualization.

Example Use Cases
Regression Analysis with Random Forest:


analysis = MLModelAnalysis(model_type='random_forest')
analysis.train_and_evaluate(csv_file='data.csv', x_elements=['feature1', 'feature2'], y_element='target', model_save_path='random_forest_model.pkl')
Quick Prediction with a Pre-trained Model:


prediction = analysis.load_model_and_predict(model_path='random_forest_model.pkl', input_data={'feature1': 5.1, 'feature2': 2.3})
print(f'Prediction: {prediction}')
Switching Models Effortlessly:


# Simply specify a new model type to use a different algorithm
analysis = MLModelAnalysis(model_type='xgboost')
Additional Notes
Plotting: Visualizations are supported for linear models and SVM with single-feature datasets.
Model Saving: The model_save_path in train_and_evaluate stores the model, scaler, and encoders, allowing consistent predictions when reloading the model later.
Dependencies: Ensure required libraries (scikit-learn, pandas, numpy, plotly, and xgboost) are installed.








# ######                                                                      image_classify:                                                                  ###### #

# example usages:

image_classifier = ImageClassifier()
image_classifier.img_train(
    train_dir='train',
    test_dir='test',  # Optional, can be None to split training data
    epochs=1,
    device='cpu',
    force='vgg16',
    finetune=True
)


image_classifier = ImageClassifier()
image_classifier.img_train(
    train_dir='train',
    test_dir='test',  # Optional, can be None to split training data
    epochs=1,
    device='cpu',
    force='vgg16'
)


# Using directory data
image_classifier = ImageClassifier()
image_classifier.img_train(
    train_dir='path/to/train',
    test_dir='path/to/test',
    epochs=10,
    device='cuda',
    force='resnet50',
    finetune=True
)

# Using CSV data
image_classifier.img_train(
    csv_file='path/to/data.csv',
    img_column='image_path',  # Column name in CSV containing image paths
    label_column='label',      # Column name in CSV containing labels
    epochs=10,
    device='cuda',
    force='resnet50',
    finetune=True
)


consist of 20 cnn architecture excluding finetuning
# Instantiate and train the classifier with a specific model and fine-tuning enabled
image_classifier = ImageClassifier()
image_classifier.img_train("path_to_train_dir", "path_to_test_dir", epochs=10, device="cuda", force="efficientnet", finetune=True)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gurulearn",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Guru Dharsan T",
    "author_email": "gurudharsan123@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/92/31/ac731f6f691338163c91884d8b476253f8d0e0d984d2bc0e3d8b6523cb92/gurulearn-1.0.18.tar.gz",
    "platform": null,
    "description": "# ######                                                                      MLModelAnalysis                                                                 ###### #\r\n\r\nMLModelAnalysis is a flexible, reusable class for training, evaluating, and making predictions with various machine learning regression models. This tool allows easy switching between models, consistent preprocessing, model evaluation, and prediction for a variety of machine learning tasks.\r\n\r\nSupported Models\r\nLinear Regression (linear_regression)\r\nDecision Tree Regressor (decision_tree)\r\nRandom Forest Regressor (random_forest)\r\nSupport Vector Machine (svm)\r\nGradient Boosting Regressor (gradient_boosting)\r\nK-Nearest Neighbors (knn)\r\nAdaBoost Regressor (ada_boost)\r\nNeural Network (MLP Regressor) (mlp)\r\nXGBoost Regressor (xgboost)\r\nUsage\r\n1. Initializing the Model\r\nInitialize the MLModelAnalysis class by specifying the model_type parameter, which defines the machine learning model you want to use. Below are examples of initializing with various models:\r\n\r\npython\r\nCopy code\r\nfrom sklearn.linear_model import LinearRegression\r\nfrom sklearn.tree import DecisionTreeRegressor\r\nfrom sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor, AdaBoostRegressor\r\nfrom sklearn.svm import SVR\r\nfrom sklearn.neighbors import KNeighborsRegressor\r\nfrom sklearn.neural_network import MLPRegressor\r\n\r\n# Initialize with Linear Regression\r\nanalysis = MLModelAnalysis(model_type='linear_regression')\r\n\r\n# Initialize with Random Forest\r\nanalysis = MLModelAnalysis(model_type='random_forest')\r\n\r\n# Initialize with XGBoost\r\nanalysis = MLModelAnalysis(model_type='xgboost')\r\n2. Training and Evaluating the Model\r\nThe train_and_evaluate method preprocesses the data, trains the model, and displays evaluation metrics. Optionally, it saves the trained model, scaler, and encoders for later use.\r\n\r\nParameters:\r\ncsv_file: Path to the CSV file containing the dataset.\r\nx_elements: List of feature columns.\r\ny_element: Name of the target column.\r\nmodel_save_path (Optional): Path to save the trained model, scaler, and encoders.\r\nExample:\r\n# Set the parameters\r\ncsv_file = 'data.csv'          # Path to the data file\r\nx_elements = ['feature1', 'feature2']  # List of feature columns\r\ny_element = 'target'            # Target column name\r\n\r\n# Initialize the model\r\nanalysis = MLModelAnalysis(model_type='random_forest')\r\n\r\n# Train and evaluate the model\r\nanalysis.train_and_evaluate(csv_file=csv_file, x_elements=x_elements, y_element=y_element, model_save_path='random_forest_model.pkl')\r\nAfter running this code, the model will display R-squared and Mean Squared Error (MSE) metrics for both training and test sets. If model_save_path is specified, it saves the model for future predictions.\r\n\r\n3. Loading the Model and Making Predictions\r\nThe load_model_and_predict method loads a saved model and makes predictions on new input data.\r\n\r\nParameters:\r\nmodel_path: Path to the saved model file (created in the previous step).\r\ninput_data: Dictionary of feature names and values representing a single input instance for prediction.\r\nExample:\r\n# Define input data for prediction\r\ninput_data = {\r\n    'feature1': 5.1,\r\n    'feature2': 2.3\r\n}\r\n\r\n# Load the model and make a prediction\r\nprediction = analysis.load_model_and_predict(model_path='random_forest_model.pkl', input_data=input_data)\r\nprint(f'Prediction: {prediction}')\r\n4. Visualization\r\nWhen using a linear_regression or svm model with only one feature, the train_and_evaluate method will automatically generate a Plotly plot of actual vs. predicted values for simple visualization.\r\n\r\nExample Use Cases\r\nRegression Analysis with Random Forest:\r\n\r\n\r\nanalysis = MLModelAnalysis(model_type='random_forest')\r\nanalysis.train_and_evaluate(csv_file='data.csv', x_elements=['feature1', 'feature2'], y_element='target', model_save_path='random_forest_model.pkl')\r\nQuick Prediction with a Pre-trained Model:\r\n\r\n\r\nprediction = analysis.load_model_and_predict(model_path='random_forest_model.pkl', input_data={'feature1': 5.1, 'feature2': 2.3})\r\nprint(f'Prediction: {prediction}')\r\nSwitching Models Effortlessly:\r\n\r\n\r\n# Simply specify a new model type to use a different algorithm\r\nanalysis = MLModelAnalysis(model_type='xgboost')\r\nAdditional Notes\r\nPlotting: Visualizations are supported for linear models and SVM with single-feature datasets.\r\nModel Saving: The model_save_path in train_and_evaluate stores the model, scaler, and encoders, allowing consistent predictions when reloading the model later.\r\nDependencies: Ensure required libraries (scikit-learn, pandas, numpy, plotly, and xgboost) are installed.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n# ######                                                                      image_classify:                                                                  ###### #\r\n\r\n# example usages:\r\n\r\nimage_classifier = ImageClassifier()\r\nimage_classifier.img_train(\r\n    train_dir='train',\r\n    test_dir='test',  # Optional, can be None to split training data\r\n    epochs=1,\r\n    device='cpu',\r\n    force='vgg16',\r\n   \u00c2\u00a0finetune=True\r\n)\r\n\r\n\r\nimage_classifier = ImageClassifier()\r\nimage_classifier.img_train(\r\n    train_dir='train',\r\n    test_dir='test',  # Optional, can be None to split training data\r\n    epochs=1,\r\n    device='cpu',\r\n   \u00c2\u00a0force='vgg16'\r\n)\r\n\r\n\r\n# Using directory data\r\nimage_classifier = ImageClassifier()\r\nimage_classifier.img_train(\r\n    train_dir='path/to/train',\r\n    test_dir='path/to/test',\r\n    epochs=10,\r\n    device='cuda',\r\n    force='resnet50',\r\n    finetune=True\r\n)\r\n\r\n# Using CSV data\r\nimage_classifier.img_train(\r\n    csv_file='path/to/data.csv',\r\n    img_column='image_path',  # Column name in CSV containing image paths\r\n    label_column='label',      # Column name in CSV containing labels\r\n    epochs=10,\r\n    device='cuda',\r\n    force='resnet50',\r\n   \u00c2\u00a0finetune=True\r\n)\r\n\r\n\r\nconsist of 20 cnn architecture excluding finetuning\r\n# Instantiate and train the classifier with a specific model and fine-tuning enabled\r\nimage_classifier = ImageClassifier()\r\nimage_classifier.img_train(\"path_to_train_dir\", \"path_to_test_dir\", epochs=10, device=\"cuda\", force=\"efficientnet\", finetune=True)\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "library for MLModelAnalysis and multi image model(bug fix 2.0)",
    "version": "1.0.18",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9519f1b8bf17322b0ff1ad5a0660cc65597543a67429fc8122dc787443770f5",
                "md5": "79881e2540a7c424336f11b5d2589141",
                "sha256": "f7e01f37e4d4de559349580efa96187b82b33330b597fd61f916db7a5e88e16e"
            },
            "downloads": -1,
            "filename": "gurulearn-1.0.18-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "79881e2540a7c424336f11b5d2589141",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9605,
            "upload_time": "2024-10-26T17:41:19",
            "upload_time_iso_8601": "2024-10-26T17:41:19.788301Z",
            "url": "https://files.pythonhosted.org/packages/c9/51/9f1b8bf17322b0ff1ad5a0660cc65597543a67429fc8122dc787443770f5/gurulearn-1.0.18-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9231ac731f6f691338163c91884d8b476253f8d0e0d984d2bc0e3d8b6523cb92",
                "md5": "5b2db7f99221b6a4d81637d610ae00f2",
                "sha256": "240196237ba64f0a3dfbd40fe2851552e7b4e6eee75625f6d88bab162aa829bc"
            },
            "downloads": -1,
            "filename": "gurulearn-1.0.18.tar.gz",
            "has_sig": false,
            "md5_digest": "5b2db7f99221b6a4d81637d610ae00f2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10771,
            "upload_time": "2024-10-26T17:41:21",
            "upload_time_iso_8601": "2024-10-26T17:41:21.286392Z",
            "url": "https://files.pythonhosted.org/packages/92/31/ac731f6f691338163c91884d8b476253f8d0e0d984d2bc0e3d8b6523cb92/gurulearn-1.0.18.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-26 17:41:21",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gurulearn"
}
        
Elapsed time: 0.77190s