<jupyter_start><jupyter_text>converting data into a dataframe<jupyter_code>df = pd.DataFrame(columns = load_breast_cancer()["feature_names"],data = load_breast_cancer()["data"])
df.head()<jupyter_output><empty_output><jupyter_text>Checking for null values<jupyter_code>df.isnull().any()
target = load_breast_cancer()["target"]
target
labels = {}
target_names = load_breast_cancer()["target_names"]
for i in range(len(target_names)):
    labels.update({i:target_names[i]})
labels<jupyter_output><empty_output><jupyter_text>Since there are no null values so we can convert the data into numpy array to feed to the network<jupyter_code>X = np.array(df)
X<jupyter_output><empty_output><jupyter_text>"nn_model" is simply the python script version of the nn_model implemented in the other jupyter notebook<jupyter_code>import nn_model as model
from sklearn.model_selection import train_test_split<jupyter_output><empty_output><jupyter_text>dividing data into train and test<jupyter_code>trainX,testX,trainY,testY = train_test_split(X,target,test_size = 0.15,shuffle = True)
print(trainX.shape)
print(testX.shape)
print(trainY.shape)
print(testY.shape)<jupyter_output>(483,)
(86,)<jupyter_text>here we transpose the train data so that features of the dataset become as rows and no: of entries become as columns.we did this because we designed our neural net like this and it is advised to feed data in neural net like this because it is easy to visualize the data like this and easy to debug later<jupyter_code>trainX = trainX.T
testX = testX.T
print(trainX.shape)
print(testX.shape)
trainY = trainY.reshape(1,len(trainY))
testY = testY.reshape(1,len(testY))
print(trainY.shape)
print(testY.shape)<jupyter_output>(1, 483)
(1, 86)<jupyter_text>defining the layers of the neural net, in this case there are total 5 layers, 1 layer is input layer, next 4 layers are hidden layers in which last layer is output layer<jupyter_code>layer_dims = [trainX.shape[0],50,20,5,1]<jupyter_output><empty_output><jupyter_text>calling the function<jupyter_code>parameters,costs = model.deep_nn_model(X = trainX, Y = trainY, layer_dims=layer_dims, num_iterations=3000, learning_rate=0.0075)<jupyter_output>cost after 0 iterations is 0.6931608088952668
cost after 100 iterations is 0.6819854505378983
cost after 200 iterations is 0.6742796054396292
cost after 300 iterations is 0.6689418871396972
cost after 400 iterations is 0.6651940017052747
cost after 500 iterations is 0.6623870515979797
cost after 600 iterations is 0.659254814523776
cost after 700 iterations is 0.6220475846010026
cost after 800 iterations is 0.5850642493350722
cost after 900 iterations is 0.5494961310760973
cost after 1000 iterations is 0.5005282816497069
cost after 1100 iterations is 0.4190346240699046
cost after 1200 iterations is 0.36522709408912235
cost after 1300 iterations is 0.34003123783992567
cost after 1400 iterations is 0.31737584071811
cost after 1500 iterations is 0.3003094331209577
cost after 1600 iterations is 0.2942990215435755
cost after 1700 iterations is 0.2671464537192814
cost after 1800 iterations is 0.2752720081337744
cost after 1900 iterations is 0.2560229273759402
cost after 2000 iterations is 0.2[...]<jupyter_text>line plot of costs<jupyter_code>plt.plot(costs)<jupyter_output><empty_output><jupyter_text>using the trained model for prediction<jupyter_code>Y_hat = model.predict(testX,parameters)<jupyter_output><empty_output><jupyter_text>converting result into 1D array<jupyter_code>Y_hat = Y_hat.reshape(-1)
testY = testY.reshape(-1)<jupyter_output><empty_output><jupyter_text>since in our output layer we used sigmoid activation function(because it is classification problem) whose values lies between 0 to 1 so we have to convert the received data into 0 or 1, if result is > 0.5 then it is 1 otherwise it is 0<jupyter_code>Y_hat = 1*(Y_hat>0.5)<jupyter_output><empty_output><jupyter_text>calculating Accuracy of the model<jupyter_code>Accuracy = sum(1*(Y_hat==testY))/len(Y_hat)*100
print("Accuracy on test data "+str(Accuracy))
Yhat = model.predict(trainX,parameters)
Yhat = Yhat.reshape(-1)
trainY = trainY.reshape(-1)
Yhat = 1*(Yhat>0.5)
Accuracy = sum(1*(Yhat==trainY))/len(Yhat)*100
print("Accuracy on train data "+str(Accuracy))<jupyter_output>Accuracy on train data 92.54658385093167
{'fraction_non_alphanumeric': 0.08734236338159738, 'fraction_numerical': 0.11489957963568426, 'mean_word_length': 7.431102362204724, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '255404', 'license': 'MIT', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1452, 'n_words': 409, 'path': 'Machine Learning Projects/Neural-Network-From-Scratch/.ipynb_checkpoints/breast cancer classification-checkpoint.ipynb', 'repo_name': 'samlaubscher/HacktoberFest2020-Contributions', 'size': '4282'}