This repository contains implementations of various Machine Learning algorithms in Python. It provides well-structured, easy-to-understand code for common ML techniques, including supervised and unsupervised learning.
- Supervised Learning: Implements algorithms like Linear Regression, Logistic Regression, Decision Trees, and Support Vector Machines (SVM).
- Unsupervised Learning: Includes clustering techniques like K-Means and Hierarchical Clustering.
- Performance Evaluation: Utilizes metrics such as accuracy, precision, recall, and confusion matrices.
- Data Preprocessing: Covers feature scaling, encoding, and handling missing values.
- Visualization: Uses Matplotlib and Seaborn for data insights and model evaluation.
To install the required libraries, run:
pip install numpy pandas scikit-learn matplotlib seabornimport numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import accuracy_score, classification_reportThese libraries are used for data handling, model training, and performance evaluation.
def load_and_preprocess_data(filepath):
df = pd.read_csv(filepath)
df.dropna(inplace=True) # Handle missing values
return dfReads the dataset and removes missing values for cleaner data.
from sklearn.linear_model import LogisticRegression
def train_logistic_regression(X, y):
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = LogisticRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(classification_report(y_test, y_pred))
return modelSplits the data, trains a Logistic Regression model, and evaluates its performance.
from sklearn.cluster import KMeans
def apply_kmeans(X, n_clusters=3):
kmeans = KMeans(n_clusters=n_clusters, random_state=42)
kmeans.fit(X)
return kmeans.labels_Applies K-Means clustering to group data into clusters.
- Clone the repository:
git clone https://github.com/Al-Scripting/Mechine-Learning-Alogrithms-- Install dependencies:
pip install -r requirements.txt- Run ML models:
python main.pyContributions are welcome! Feel free to open issues or pull requests.
This project is open-source and available under the MIT License.