Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement logging throughout the package Labels #6 #41

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion createDB.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import numpy as np
import pandas as pd
import logging


logger=logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# Set seed for reproducibility
logger.debug("Setting the speed...")
np.random.seed(42)

# Generate 100 rows of data
logger.debug("Setting up the data...")
data_size = 100

# Generate 4 features with random values
# Feature 1: Age (18 to 90)
logger.debug("Generating the features...")
age = np.random.randint(18, 90, data_size)

# Feature 2: Tumor size (1 to 10 cm)
Expand All @@ -22,11 +29,14 @@

# Generate target column 'Cancer' based on some logic
# For simplicity, assume higher risk if age > 50, tumor_size > 5, gene_mutation = 1, and smoking_history > 20
logger.debug("Generating the column...")
cancer_risk = (age > 50) & (tumor_size > 5) & (gene_mutation == 1) & (smoking_history > 20)
cancer = np.where(cancer_risk, 1, 0)

# Create a DataFrame
logger.debug("Creating the DataFrame...")
df = pd.DataFrame({

'Age': age,
'Tumor_Size': tumor_size,
'Gene_Mutation': gene_mutation,
Expand All @@ -35,6 +45,7 @@
})

# Save the DataFrame to a CSV file
logger.info("Saving the csv file...")
df.to_csv('cancer.csv', index=False)

print("CSV file 'cancer.csv' has been created.")
logger.info("CSV file 'cancer.csv' has been created.")
2 changes: 2 additions & 0 deletions explainableai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# explainableai/__init__.py
from .core import XAIWrapper

import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
__all__ = ['XAIWrapper']
18 changes: 15 additions & 3 deletions explainableai/anomaly_detection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from sklearn.ensemble import IsolationForest
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
def detect_anomalies(X):
iso_forest = IsolationForest(contamination=0.1, random_state=42)
anomalies = iso_forest.fit_predict(X)
return anomalies
try:
#Creating an Isolation forest
logger.debug("Creating isolation forest model...")
iso_forest = IsolationForest(contamination=0.1, random_state=42)

#Prediction
logger.debug("Making Prediction...")
anomalies = iso_forest.fit_predict(X)
logger.info("Prediction Maked...")
return anomalies
except Exception as e:
logger.error(f"Something wrong in the prediction...{str(e)}")
Loading
Loading