Skip to content

Instantly share code, notes, and snippets.

View sagarhowal's full-sized avatar
💭
commit-ment issues

Sagar Howal sagarhowal

💭
commit-ment issues
  • Dublin, Ireland
View GitHub Profile
@sagarhowal
sagarhowal / keras_predict_ann.py
Created December 25, 2017 10:49
Predicting the Test set results and Confusion Matrix in Keras
# Predicting the Test set results
y_pred = classifier.predict(X_test)
y_pred = (y_pred > 0.5)
# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
@sagarhowal
sagarhowal / ann_fitting.py
Created December 25, 2017 10:48
Fitting an ANN
# Fitting the ANN to the Training set
classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)
@sagarhowal
sagarhowal / create_ANN_keras.py
Created December 25, 2017 10:47
ANN Design and Compiling
# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu', input_dim = 30))
# Adding the second hidden layer
classifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu'))
# Adding the output layer
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))
# Compiling the ANN
@sagarhowal
sagarhowal / init_sequential.py
Created December 25, 2017 10:46
Initialising the ANN
# Initialising the ANN
classifier = Sequential()
@sagarhowal
sagarhowal / import_keras.py
Created December 25, 2017 10:45
Importing the Keras libraries and packages
# Importing the Keras libraries and packages
import keras
from keras.models import Sequential
from keras.layers import Dense
@sagarhowal
sagarhowal / splitting_train_test.py
Created December 25, 2017 10:44
Splitting into Training set and Test set
#Splitting into Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)
@sagarhowal
sagarhowal / LabelEncoder.py
Last active December 25, 2017 10:43
Encoding Categorical Data
#Encoding Categorical Data
from sklearn.preprocessing import LabelEncoder
labelencoder = LabelEncoder()
y = labelencoder.fit_transform(y)
@sagarhowal
sagarhowal / X_and_y.py
Created December 25, 2017 10:42
Separating X and y
#Seperating dependent and independent variables.
X = dataset.iloc[:, 2:32].values #Note: Exclude Last column with all NaN values.
y = dataset.iloc[:, 1].values
@sagarhowal
sagarhowal / np_read_csv.py
Created December 25, 2017 10:41
Reading CSV File with NumPy
import numpy as np
import pandas as pd
#Importing dataset
dataset = pd.read_csv('breast_cancer.csv')
#Check the first 5 rows of the dataset.
dataset.head(5)
@sagarhowal
sagarhowal / upload_and_read_colaboratory.py
Created December 25, 2017 10:38
Upload Dataset on Google Colaboratory.
#Uploading the Dataset
from google.colab import files
uploaded = files.upload()
#Save uploaded file on the Virtual Machine's
#Thanks to user3800642 from StackOverflow
with open("breast_cancer.csv", 'w') as f:
f.write(uploaded[uploaded.keys()[0]])