<jupyter_start><jupyter_text><jupyter_code># Finding the directory we are in
!ls<jupyter_output>datalab<jupyter_text>Next code block will mount your google drive. This will help you to access files stored in your google drive. Druing installation you see a prompt with a link -Please, open the following URL in a web browser: https://accounts.google.com/o ....Click the link. Copy and paste the code from the link in the form field and press enter. Sometime You may have to run this code block twice. I think this is a bug in colab.<jupyter_code>!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
# Mount your google drive to access files from it 
!mkdir -p drive
!google-drive-ocamlfuse drive
# The image folder that I am using for this tutorial is located in my google drive under 'app' folder
# So we need to change directory to the 'app' folder

import os
os.chdir("drive/app")
# make sure that we are in the right folder 
!ls
# importing turicreate as tc

import turicreate as tc
# Loading the images from MelanomaImages in my google drive. This 'MelanomaImages' has 2 folders
# 'melanoma' and 'benign'


data = tc.image_analysis.load_images('MelanomaImages', with_path=True)
# Labelling each images in the SFrame using the folder name

data['label'] = data['path'].apply(lambda path: 'melanoma' if '/melanoma' in path else 'benign')
#Displaying the first 5 rows in data to make sure that we got everything right 

data.tail()
# Saving the data frame to our google drive 
data.save('melanoma.sframe')
# Splitting the image data set into training (80%) and testing (20%) data
train_data, test_data = data.random_split(0.8)
# Switching to the root directory in our google virtual machine
os.chdir("/usr")
# installing other packahes to use GPU
!apt install libnvrtc8.0
# uninstalling previous versions of mxnet
!pip uninstall -y mxnet
# Installing the latest version of mxnet to work with turi create
!pip install mxnet==1.1.0
# making sure that mxnet is working
# If you get an error here, you need to fix it before going forward
import mxnet as m2
# Automatically pick the right model based on your data.
# Note: Because the dataset is large, model creation may take hours.

model = tc.image_classifier.create(train_data, target='label')<jupyter_output>Downloading https://docs-assets.developer.apple.com/turicreate/models/resnet-50-symbol.json
Download completed: /var/tmp/model_cache/resnet-50-symbol.json
Downloading https://docs-assets.developer.apple.com/turicreate/models/resnet-50-0000.params
Download completed: /var/tmp/model_cache/resnet-50-0000.params
Resizing images...
Performing feature extraction on resized images...
Completed 512/734
Completed 734/734
PROGRESS: Creating a validation set from 5 percent of training data. This may take a while.
          You can set ``validation_set=None`` to disable validation tracking.<jupyter_text>Took only about 7 minutes to do this with GPU!<jupyter_code># storing the prediction 

predictions = model.predict(test_data)
# Evaluating the model 

metrics = model.evaluate(test_data)
print(metrics['accuracy'])
# Printing confusion matrix

print ("Confusion Matrix : \n%s" % metrics['confusion_matrix'])<jupyter_output>Confusion Matrix : 
+--------------+-----------------+-------+
| target_label | predicted_label | count |
+--------------+-----------------+-------+
|    benign    |      benign     |  102  |
|    benign    |     melanoma    |   7   |
|   melanoma   |     melanoma    |   49  |
|   melanoma   |      benign     |   25  |
+--------------+-----------------+-------+
[4 rows x 3 columns]<jupyter_text>```> Statistic           Value            Confidence interval > Sensitivity         66.22%	        54.28% to 76.81%> Specificity         93.58 %	       87.22% to 97.38%> PPV                 87.50%    	    77.05% to 93.59%> NPV                 80.31 %           74.71% to 84.93%> Accuracy            82.51% 	       76.22% to 87.72%```<jupyter_code># Save the model for later use in Turi Create
model.save('melanoma.model')
# Export for use in Core ML
model.export_coreml('MyMelanomaClassifier.mlmodel')
!ls
# Downloading the model for use in Xcode

from google.colab import files

files.download('MyMelanomaClassifier.mlmodel')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11535286834502682, 'fraction_numerical': 0.024969046636401156, 'mean_word_length': 3.5172413793103448, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '355070', 'license': 'MIT', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1476, 'n_words': 520, 'path': 'melanoma_classification (1).ipynb', 'repo_name': 'johnyquest7/Melanoma', 'size': '4846'}