<jupyter_start><jupyter_text>Breast cancer analysis using Ludwig<jupyter_code>import pandas as pd
import time

import warnings
warnings.filterwarnings('ignore')
# Read data from local directory
breast_cancer_dataset = pd.read_csv('./breast_cancer_dataset.csv')
# Split data for training and testing
from sklearn.model_selection import train_test_split

split = 0.3
breast_cancer_dataset_train, breast_cancer_dataset_test = train_test_split(breast_cancer_dataset, 
                                                                           test_size=split)
X_test = breast_cancer_dataset_test.drop(columns='label')
Y_test = breast_cancer_dataset_test['label']
# Train locally defined Ludwig model
from ludwig.api import LudwigModel

start_time = time.time()
model = LudwigModel(model_definition_file='./LudwigModelDefinitionFile.yml')
train_stats = model.train(data_df=breast_cancer_dataset_train,
                          skip_save_model=True, 
                          skip_save_processed_input=True, 
                          skip_save_training_statistics=True, 
                          skip_save_training_description=True, 
                          skip_save_log=True, 
                          skip_save_progress=True)
training_time = time.time() - start_time
# Visualize training statistics
from ludwig.visualize import learning_curves

learning_curves(train_stats, output_feature_name='label')
# Predict and print statistics
pred = model.predict(data_df=X_test)
predictions = pred['label_predictions']
Y_test = Y_test == 1  # Change labels from 0/1 to False/True

pred_correct = []
for i in range(1, len(Y_test)):
    pred_correct.append(predictions.iloc[i-1] == Y_test.iloc[i-1])

print("No. of correct predictions = {}".format(sum(pred_correct)))
print("No. of incorrect predictions = {}".format(len(Y_test)-sum(pred_correct)))
print("Training time = {} seconds".format(round(training_time,2)))

model.close()<jupyter_output>No. of correct predictions = 158
No. of incorrect predictions = 13
Training time = 2.16 seconds
{'fraction_non_alphanumeric': 0.08845208845208845, 'fraction_numerical': 0.008353808353808353, 'mean_word_length': 3.6378132118451023, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '316810', 'license': 'MIT', 'n_tokens_mistral': 616, 'n_tokens_neox': 580, 'n_words': 125, 'path': 'Ludwig/MyLudwig/BreastCancerAnalysisViaLudwig.ipynb', 'repo_name': 'snigdhayan/NeuralNetworks', 'size': '2035'}