This is a good simple example of a classification problem utilizing Keras and Tensorflow. In addition, I'm utilizing early stopping in an attempt to avoid overfitting in the model. You'll notice this take effect as the model stops training well before the 600 set epochs.
Keras / Tensorflow Classification - ExampleHere we're going to attempt to utilize Keras/Tensorflow to predict the whether or not an individual has cancer.
The data being used can be seen on my github below:
https://github.com/kaledev/PythonSnippets/blob/master/Datasets/Keras/cancer_classification.csv
Data Imports and EDA
In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
In [2]:
df = pd.read_csv('DATA/cancer_classification.csv')
Here we can see the dataset is fairly well balanced in terms of classification of the labels, if the dataset was unbalanced then we might see issues with overfitting.
In [3]:
sns.countplot(x='benign_0__mal_1',data=df)
Out[3]:
<AxesSubplot:xlabel='benign_0__mal_1', ylabel='count'>
Create Models and Predict
In [4]:
#Set X/y
X = df.drop('benign_0__mal_1', axis=1).values
y = df['benign_0__mal_1'].values
In [5]:
from sklearn.model_selection import train_test_split
In [6]:
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
We need to scale the data so all features are in sync
In [7]:
from sklearn.preprocessing import MinMaxScaler
In [8]:
scaler = MinMaxScaler()
In [9]:
X_train =...