<jupyter_start><jupyter_text>Breast Cancer Data Exploration (UCI)For Dr. LaGrassa's Bioinformatics ClassTutorial 5?<jupyter_code>import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
batch_data = load_iris()
print(batch_data['DESCR'])<jupyter_output>.. _iris_dataset:

Iris plants dataset
--------------------

**Data Set Characteristics:**

    :Number of Instances: 150 (50 in each of three classes)
    :Number of Attributes: 4 numeric, predictive attributes and the class
    :Attribute Information:
        - sepal length in cm
        - sepal width in cm
        - petal length in cm
        - petal width in cm
        - class:
                - Iris-Setosa
                - Iris-Versicolour
                - Iris-Virginica
                
    :Summary Statistics:

    ============== ==== ==== ======= ===== ====================
                    Min  Max   Mean    SD   Class Correlation
    ============== ==== ==== ======= ===== ====================
    sepal length:   4.3  7.9   5.84   0.83    0.7826
    sepal width:    2.0  4.4   3.05   0.43   -0.4194
    petal length:   1.0  6.9   3.76   1.76    0.9490  (high!)
    petal width:    0.1  2.5   1.20   0.76    0.9565  (high!)
    ============== ==== ==== ======= ===== ===========[...]<jupyter_text>Attribute Information:         sepal length in cm          sepal width in cm          petal length in cm          petal width in cm  Class:      Iris-Setosa     Iris-Versicolour      Iris-Virginica<jupyter_code>columns = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width']
df = pd.DataFrame(batch_data['data'], columns=columns)
df['target'] = batch_data['target']
df<jupyter_output><empty_output><jupyter_text>EDA Time<jupyter_code># Can examine top of dataframe with head or tail()
df.head()
df.tail()
# For categorical data
df['sepal-length'].value_counts()
df['sepal-length'].hist()
df['sepal-width'].hist()
# ARE THE CLASSES EQUAL? CLASS IMBALANCE?
df['target'].hist()
df.describe()
df.plot(kind='scatter', x='sepal-length', y='sepal-width')
df.plot(kind='scatter', x='petal-length', y='petal-width')<jupyter_output><empty_output><jupyter_text>Imputing<jupyter_code>import random
import numpy as np

items = [random.randint(1, 100) if i % 2 == 0 else np.nan for i in range(150)]
print(len(items))

df['extra'] = items
items
df.head()
from sklearn.impute import SimpleImputer
impute = SimpleImputer(missing_values=np.nan, strategy="median")
impute.fit(df[['extra']])

df['extra'] = impute.transform(df[['extra']])
df.head()

del df['extra']
df.head()<jupyter_output><empty_output><jupyter_text>Simple ML<jupyter_code># Classification Time with a SVM
from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(df.drop('target', axis=1), df['target'])
from sklearn.neighbors import KNeighborsClassifier

knn = KNeighborsClassifier()
knn.fit(x_train, y_train)
y_pred = knn.predict(x_test)
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score

print(f'--> Accuracy Score: {accuracy_score(y_test, y_pred)}')
print()
print(f'Precision Score: {precision_score(y_test, y_pred, average ="macro")}')
print(f'Recall Score: {recall_score(y_test, y_pred, average ="macro")}')
print(f'--> F1 Score: {f1_score(y_test, y_pred, average ="macro")}')<jupyter_output>--> Accuracy Score: 0.9736842105263158

Precision Score: 0.9761904761904763
Recall Score: 0.9666666666666667
--> F1 Score: 0.9701104613385315
{'fraction_non_alphanumeric': 0.17045781744889144, 'fraction_numerical': 0.042902389864670314, 'mean_word_length': 3.8451882845188283, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '329227', 'license': 'MIT', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1203, 'n_words': 283, 'path': 'EDA Iris.ipynb', 'repo_name': 'AstroNoodles/Mini-Projects', 'size': '3473'}