Example #1
0
#
Implementation of DecisionTreeClassification on BreastCancerData
#

import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score, roc_auc_score,classification_report
from sklearn.decomposition import PCA
import pandas as pd
from utils.utils_scores import scores

flag_pca = False

data, target = load_breast_cancer(return_X_y=True)
data = pd.DataFrame(data)
target = pd.DataFrame(target)

if flag_pca:
    pca = PCA()
    data = pca.fit_transform(data)

data_train, data_test, target_train, target_test = train_test_split(data, target, test_size=0.1,random_state=0)

DecisionTreeClassifierObject = DecisionTreeClassifier()
DecisionTreeClassifierObject.fit(data_train, target_train)

target_test_predict = DecisionTreeClassifierObject.predict(data_test)
scores(target_test,target_test_predict)
Example #2
0
data, target = load_breast_cancer(return_X_y=True)
data = pd.DataFrame(data)
target = pd.DataFrame(target)
target = to_categorical(target)
if flag_pca:
    pca = PCA()
    data = pca.fit_transform(data)

data_train, data_test, target_train, target_test = train_test_split(data, target, test_size=0.1, random_state=0)

input_shape = len(data_train.columns)

model = Sequential()
# Input - Layer
model.add(layers.Dense(50, activation="relu", input_shape=(input_shape,)))
# Hidden - Layers
model.add(layers.Dropout(0.3, noise_shape=None, seed=None))
model.add(layers.Dense(50, activation="relu"))
model.add(layers.Dropout(0.2, noise_shape=None, seed=None))
model.add(layers.Dense(50, activation="relu"))
# Output- Layer
model.add(layers.Dense(2, activation="sigmoid"))
model.summary()

model.compile(optimizer='adam', loss="binary_crossentropy",
              metrics=["accuracy"])
model.fit(data_train, target_train, epochs=50, verbose=1)
y_predict = model.predict(data_test)

scores(pd.DataFrame(target_test), pd.DataFrame(y_predict.round()))