Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 266
# Convolutional Neural Network # Detection of Pulmonary embolism # Goal: Train a model to detect a pulmonary embolism by perceiving the little details on pulmonary radiology images, that human eyes would miss, by using CNN filters techniques also known as feature detectors also know as Kernel # Comparison between the X-ray image of a healthy lung and a pulmonary embolism image # Spatial invariance # -*- coding: utf-8 -*- """ Created on Mon May 1 20:33:41 2019 @author: Florent """ # Part 1 - Building the CNN # Importing the Keras libraries and packages from keras.models import Sequential from keras.layers import Convolution2D from keras.layers import MaxPooling2D from keras.layers import Flatten from keras.layers import Dense # Initialising the CNN classifier = Sequential() # Step 1 - Convolution classifier.add(Convolution2D(40, 4, 4, input_shape = (103, 103, 3), activation = 'relu')) # Step 2 - Pooling classifier.add(MaxPooling2D(pool_size = (2, 2))) # Adding a second convolutional layer classifier.add(Convolution2D(32, 3, 3, activation = 'relu')) classifier.add(MaxPooling2D(pool_size = (2, 2))) # Step 3 - Flattening classifier.add(Flatten()) # Step 4 - Full connection classifier.add(Dense(output_dim = 130, activation = 'relu')) classifier.add(Dense(output_dim = 1, activation = 'sigmoid')) # Compiling the CNN classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) # Part 2 - Fitting the CNN to the images from keras.preprocessing.image import ImageDataGenerator train_datagen = ImageDataGenerator(rescale = 1./255, shear_range = 0.2, zoom_range = 0.2, horizontal_flip = True) test_datagen = ImageDataGenerator(rescale = 1./255) training_set = train_datagen.flow_from_directory('dataset/training_set', target_size = (103, 103), batch_size = 32, class_mode = 'binary') test_set = test_datagen.flow_from_directory('dataset/test_set', target_size = (103, 103), batch_size = 32, class_mode = 'binary') classifier.fit_generator(training_set, samples_per_epoch = 10000, nb_epoch = 25, validation_data = test_set, nb_val_samples = 2000) # Part 3 Making New Prediction import numpy as np from keras.preprocessing import image test_image = image.load_img('dataset/predict/Healthy_or_Embolism.jpg', target_size = (64,64)) test_image = image_to_array(test_image) test_image = np.expand_dims(test_image, axis =0) result = classifier.predict(test_image) training_set.class_indices if result[0][0] ==1: prediction = 'Embolism' else: prediction = 'Healthy' Result : Embolism ## END Of THE PROJECT ## MACHINE LEARNING PROJECT ## # Artificial Neural Network (ANN) # Goal: Prediction on customers' behavior for HOOCH Inc. # Deep Learning # Type of Activation function: Sigmoid function # Cathegorical variables # Optimizing # Creating and Training a model for HOOCH Inc. # Found Trained Model Accuracy Accuracy of 0.86 # -*- coding: utf-8 -*- """ Created on Mon Oct 1 10:46:52 2018 @author: Florent """ import numpy as np import matplotlib.pyplot as plt import pandas as pd # Importing the dataset dataset = pd.read_csv('Customers_Company.csv') X = dataset.iloc[:, 3:17].values y = dataset.iloc[:, 12].values # Encoding cathegorical data from sklearn.preprocessing import LabelEncoder, OneHotEncoder labelencoder_X_1 = LabelEncoder() X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1]) labelencoder_X_2 = LabelEncoder() X[:, 3] = labelencoder_X_3.fit_transform(X[:, 3]) onehotencoder = OneHotEncoder(cathegorical_features = [1]) X = onehotencoder.fit_transform(X).toarray() # Spitting the dataset into the Training set and Test set from sklearn.cross_validation import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) # Feature Sealing from sklearn.preprocessing import StandardScaler sc = StandardScaler() X_train = sc.fit_transform(X_train) X_test = sc.transform(X_test) # Making the ANN # Importing the keras Libraries import keras from keras.models import Sequential from keras.layers import Dense from keras.layers import Dropout # Initialising the ANN classifier = Sequential() # Adding the input layer and the first hidden layer classifier.add(Dense(output_dim = 6, init = 'uniform', activation = 'relu', input_dim = 11)) classifier.add(Dropout(p =0.1)) # Adding the second hidden layer classifier.add(Dense(output_dim = 6, init = 'uniform', activation = 'relu')) classifier.add(Dropout(p =0.1)) # Adding the output layer classifier.add(Dense(output_dim = 1, init = 'uniform', activation = 'sigmoid')) # Compiling the ANN classifier.compile(optimizer = 'adam', loss = 'binary_crossenttropy', metrics = ['accuracy']) #Fitting the ANN to the training set classifier.fit(X_train, y_train, batch_size = 10, nb_epoch = 100) # 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) # Accuracy of the model: 0.86 "Accuracy of the Trained Dataset" ## EVALUATION OF THE ROOTS OF SECOND DEGREE POLYNOMIALS ## # How to evalutate the roots of second degree polynomials # Programming language used: Python # Example of polynomials utility: solving real world problems by establishing a profit function constraints, that profit function will be studied in order to maximize a company's profit # Excecute the program by pressing the buttons "Shift + Enter" or by Using Python 3.6.0 Shell (a better ground for excecuting Python codes) import math import sys print("Hello!") print("Your second degree polynomial will be the form: a X^2+ b X+ c =0") a = float(input("Enter a: ")) b = float(input("Enter b: ")) c = float(input("Enter c: ")) #Discriminant method also known as delta method Delta = b*b-(4*a*c) if Delta < 0: print("The solutions are complexe numbers") sys.exit() sqrtDelta = math.sqrt(Delta) if Delta > 0: root1 = (-b+sqrtDelta)/2*a root2 = (-b-sqrtDelta)/2*a print("The solutions are: Root 1 = " + str (root1) + " and Root 2 = " + str(root2)) elif Delta == 0: root = -b/2*a print("The double solution is:" + str (root))
Hello! Your second degree polynomial will be the form: a X^2+ b X+ c =0
Enter a:
Enter b:
Enter c:
The solutions are: Root 1 = -0.585786437627 and Root 2 = -3.41421356237