Skip to main content

Posts

Showing posts from January 20, 2025

Multiple Ensemble to find best Hyperparameters

Below is a Python implementation of a machine learning pipeline class that supports LightGBM , XGBoost , CatBoost , and AdaBoost , using RandomizedSearchCV to find the best hyperparameters. The output includes the best hyperparameters for each model in JSON format. Prerequisites Install required libraries: pip install lightgbm xgboost catboost scikit-learn pandas numpy Code: Machine Learning Pipeline Class import json import numpy as np from sklearn.model_selection import RandomizedSearchCV, train_test_split from sklearn.ensemble import AdaBoostClassifier from xgboost import XGBClassifier from lightgbm import LGBMClassifier from catboost import CatBoostClassifier from sklearn.metrics import accuracy_score class MLBoostPipeline: def __init__(self, random_state=42, n_iter=20, cv=5): self.random_state = random_state self.n_iter = n_iter self.cv = cv self.models = { "LightGBM": LGBMClassifier(random_state=self.r...

Multiple Ensemble to find best Hyperparameters

Below is a Python implementation of a machine learning pipeline class that supports LightGBM , XGBoost , CatBoost , and AdaBoost , using RandomizedSearchCV to find the best hyperparameters. The output includes the best hyperparameters for each model in JSON format. Prerequisites Install required libraries: pip install lightgbm xgboost catboost scikit-learn pandas numpy Code: Machine Learning Pipeline Class import json import numpy as np from sklearn.model_selection import RandomizedSearchCV, train_test_split from sklearn.ensemble import AdaBoostClassifier from xgboost import XGBClassifier from lightgbm import LGBMClassifier from catboost import CatBoostClassifier from sklearn.metrics import accuracy_score class MLBoostPipeline: def __init__(self, random_state=42, n_iter=20, cv=5): self.random_state = random_state self.n_iter = n_iter self.cv = cv self.models = { "LightGBM": LGBMClassifier(random_state=self.r...

Langchain AI agent with Gemini AI Api

Integrating Gemini AI API with LangChain AI agents allows you to create a more dynamic and intelligent data science pipeline. Below is an example of how to accomplish this: --- Steps to Integrate Gemini AI with LangChain 1. Set Up Gemini API: Use the Gemini AI API for specific tasks like preprocessing, training, and evaluating. 2. Define Tools: Use LangChain's Tool class to wrap Gemini API functions. 3. Create a LangChain Agent: The agent orchestrates the tools and interacts with the Gemini API. --- Python Code Prerequisites Install the required libraries: pip install langchain openai requests pandas Code import requests import pandas as pd from langchain.agents import initialize_agent, Tool from langchain.llms import OpenAI # Set your Gemini API key and endpoint API_KEY = "your_gemini_api_key" BASE_URL = "https://api.gemini.ai/v1" # Replace with actual Gemini API base URL # Define helper functions for the Gemini AI API def preprocess_data_gemini(da...