{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-10-26T03:17:54.574232Z","iopub.execute_input":"2023-10-26T03:17:54.574619Z","iopub.status.idle":"2023-10-26T03:17:55.151649Z","shell.execute_reply.started":"2023-10-26T03:17:54.574587Z","shell.execute_reply":"2023-10-26T03:17:55.15077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nImage.MAX_IMAGE_PIXELS = None\nfrom pathlib import Path\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport matplotlib as mpl\nfrom IPython.display import display\n%matplotlib inline\nfrom skimage.feature import hog\nfrom skimage.color import rgb2gray\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.decomposition import PCA\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.svm import SVC\nfrom sklearn.metrics import roc_curve, auc, accuracy_score\nfrom skimage import data\nfrom skimage.color import rgb2hed, hed2rgb","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:55.153292Z","iopub.execute_input":"2023-10-26T03:17:55.154419Z","iopub.status.idle":"2023-10-26T03:17:56.636168Z","shell.execute_reply.started":"2023-10-26T03:17:55.154375Z","shell.execute_reply":"2023-10-26T03:17:56.635175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**SAMPLE IMAGE**","metadata":{}},{"cell_type":"code","source":"img = Image.open(\"/kaggle/input/UBC-OCEAN/train_thumbnails/12442_thumbnail.png\")","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.637605Z","iopub.execute_input":"2023-10-26T03:17:56.637938Z","iopub.status.idle":"2023-10-26T03:17:56.663428Z","shell.execute_reply.started":"2023-10-26T03:17:56.637894Z","shell.execute_reply":"2023-10-26T03:17:56.662274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**IMPORTING TRAINING DATASET**","metadata":{}},{"cell_type":"code","source":"train_photodf = pd.read_csv(\"/kaggle/input/UBC-OCEAN/train.csv\")\ntrain_photodf.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.666426Z","iopub.execute_input":"2023-10-26T03:17:56.666765Z","iopub.status.idle":"2023-10-26T03:17:56.700851Z","shell.execute_reply.started":"2023-10-26T03:17:56.666736Z","shell.execute_reply":"2023-10-26T03:17:56.699688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_photodf_index = pd.read_csv(\"/kaggle/input/UBC-OCEAN/train.csv\",index_col=0)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.702558Z","iopub.execute_input":"2023-10-26T03:17:56.703517Z","iopub.status.idle":"2023-10-26T03:17:56.720821Z","shell.execute_reply.started":"2023-10-26T03:17:56.703477Z","shell.execute_reply":"2023-10-26T03:17:56.719532Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_files = []\n# giving directory name\ndirname = '/kaggle/input/UBC-OCEAN/train_thumbnails'\n \n# giving file extension\next = ('_thumbnail.png')\n \n# iterating over all files\nfor files in os.listdir(dirname):\n    if files.endswith(ext):\n        list_files.append(files)  \n    else:\n        continue","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.722655Z","iopub.execute_input":"2023-10-26T03:17:56.723049Z","iopub.status.idle":"2023-10-26T03:17:56.729963Z","shell.execute_reply.started":"2023-10-26T03:17:56.723015Z","shell.execute_reply":"2023-10-26T03:17:56.728785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_files_array = np.array(list_files)\n# list_files_array[0]","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.731521Z","iopub.execute_input":"2023-10-26T03:17:56.731959Z","iopub.status.idle":"2023-10-26T03:17:56.745858Z","shell.execute_reply.started":"2023-10-26T03:17:56.731897Z","shell.execute_reply":"2023-10-26T03:17:56.744886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_images = [item.split('_thumbnail.png')[0] for item in list_files_array]\nid_images = list(map(int, id_images))\n# id_images[0]","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.747483Z","iopub.execute_input":"2023-10-26T03:17:56.748154Z","iopub.status.idle":"2023-10-26T03:17:56.758765Z","shell.execute_reply.started":"2023-10-26T03:17:56.748122Z","shell.execute_reply":"2023-10-26T03:17:56.757747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_thumbnail = train_photodf[train_photodf['image_id'].isin(id_images)]\ndf_thumbnail.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.760025Z","iopub.execute_input":"2023-10-26T03:17:56.760478Z","iopub.status.idle":"2023-10-26T03:17:56.780289Z","shell.execute_reply.started":"2023-10-26T03:17:56.760439Z","shell.execute_reply":"2023-10-26T03:17:56.779396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_thumbnail.set_index('image_id', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.784552Z","iopub.execute_input":"2023-10-26T03:17:56.785255Z","iopub.status.idle":"2023-10-26T03:17:56.79153Z","shell.execute_reply.started":"2023-10-26T03:17:56.785224Z","shell.execute_reply":"2023-10-26T03:17:56.790574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_thumbnail.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.79318Z","iopub.execute_input":"2023-10-26T03:17:56.793791Z","iopub.status.idle":"2023-10-26T03:17:56.809343Z","shell.execute_reply.started":"2023-10-26T03:17:56.793754Z","shell.execute_reply":"2023-10-26T03:17:56.808249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_photodf.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.810836Z","iopub.execute_input":"2023-10-26T03:17:56.811454Z","iopub.status.idle":"2023-10-26T03:17:56.82798Z","shell.execute_reply.started":"2023-10-26T03:17:56.81142Z","shell.execute_reply":"2023-10-26T03:17:56.826842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_photodf_index.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.829667Z","iopub.execute_input":"2023-10-26T03:17:56.830271Z","iopub.status.idle":"2023-10-26T03:17:56.841384Z","shell.execute_reply.started":"2023-10-26T03:17:56.830239Z","shell.execute_reply":"2023-10-26T03:17:56.840257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_photodf[\"label\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.842492Z","iopub.execute_input":"2023-10-26T03:17:56.843524Z","iopub.status.idle":"2023-10-26T03:17:56.856035Z","shell.execute_reply.started":"2023-10-26T03:17:56.84349Z","shell.execute_reply":"2023-10-26T03:17:56.854929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_photodf[\"is_tma\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.857176Z","iopub.execute_input":"2023-10-26T03:17:56.857555Z","iopub.status.idle":"2023-10-26T03:17:56.87308Z","shell.execute_reply.started":"2023-10-26T03:17:56.857526Z","shell.execute_reply":"2023-10-26T03:17:56.871981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_photodf.sort_values(\"image_id\")","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.874699Z","iopub.execute_input":"2023-10-26T03:17:56.875067Z","iopub.status.idle":"2023-10-26T03:17:56.895839Z","shell.execute_reply.started":"2023-10-26T03:17:56.875037Z","shell.execute_reply":"2023-10-26T03:17:56.894715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_photodf_index.sort_index()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.897154Z","iopub.execute_input":"2023-10-26T03:17:56.898193Z","iopub.status.idle":"2023-10-26T03:17:56.913983Z","shell.execute_reply.started":"2023-10-26T03:17:56.898153Z","shell.execute_reply":"2023-10-26T03:17:56.912811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_image (row_id, root=\"/kaggle/input/UBC-OCEAN/train_images\"):\n    \"\"\"\n    Converts an image number into the file path where the image is located,\n    opens the image, return the image as numpy array.\n    \n    \"\"\"\n    filename = \"{}.png\".format(row_id)\n    file_path = os.path.join(root, filename)\n    img = Image.open(file_path)\n    new_size = (2000,2000)\n    img = img.resize(new_size)\n    return np.array(img)\n\nTumorImg = train_photodf_index[train_photodf_index.is_tma == True].index[24]\nNonTumorImg = train_photodf_index[train_photodf_index.is_tma == False].index[24]\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.915685Z","iopub.execute_input":"2023-10-26T03:17:56.916018Z","iopub.status.idle":"2023-10-26T03:17:56.928039Z","shell.execute_reply.started":"2023-10-26T03:17:56.915991Z","shell.execute_reply":"2023-10-26T03:17:56.926993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_image2 (row_id, root=\"/kaggle/input/UBC-OCEAN/train_images\"):\n    \"\"\"\n    Converts an image number into the file path where the image is located,\n    opens the image, return the image as numpy array.\n    \n    \"\"\"\n    filename = \"{}.png\".format(row_id)\n    file_path = os.path.join(root, filename)\n    img = Image.open(file_path)\n    new_size = (1000,1000)\n    img = img.resize(new_size)\n    return np.array(img)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.929352Z","iopub.execute_input":"2023-10-26T03:17:56.929774Z","iopub.status.idle":"2023-10-26T03:17:56.941343Z","shell.execute_reply.started":"2023-10-26T03:17:56.929737Z","shell.execute_reply":"2023-10-26T03:17:56.940322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_image3 (row_id, root=\"/kaggle/input/UBC-OCEAN/train_thumbnails\"):\n    \"\"\"\n    Converts an image number into the file path where the image is located,\n    opens the image, return the image as numpy array.\n    \n    \"\"\"\n    filename = \"{}_thumbnail.png\".format(row_id)\n    file_path = os.path.join(root, filename)\n    img = Image.open(file_path)\n    new_size = (1000,1000)\n    img = img.resize(new_size)\n    return np.array(img)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.942706Z","iopub.execute_input":"2023-10-26T03:17:56.943159Z","iopub.status.idle":"2023-10-26T03:17:56.953517Z","shell.execute_reply.started":"2023-10-26T03:17:56.943117Z","shell.execute_reply":"2023-10-26T03:17:56.952517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm import tqdm","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.954954Z","iopub.execute_input":"2023-10-26T03:17:56.955474Z","iopub.status.idle":"2023-10-26T03:17:56.970416Z","shell.execute_reply.started":"2023-10-26T03:17:56.95543Z","shell.execute_reply":"2023-10-26T03:17:56.969207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ndef create_features(img):\n    color_features = img.flatten()\n    gray_image = rgb2gray(img)\n    hog_features = hog(gray_image, block_norm='L2-Hys', pixels_per_cell=(16,16))\n    flat_features = np.hstack([color_features,hog_features])\n    return flat_features\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.972232Z","iopub.execute_input":"2023-10-26T03:17:56.972579Z","iopub.status.idle":"2023-10-26T03:17:56.984548Z","shell.execute_reply.started":"2023-10-26T03:17:56.972551Z","shell.execute_reply":"2023-10-26T03:17:56.983667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def create_feature_matrix(T_dataframe,T_dataframe1):\n    features_list = []\n    \n    for img_Id in tqdm(T_dataframe1.index[0:200]):\n        Img = get_image3(img_Id)\n        Image_features = create_features(Img)\n        features_list.append(Image_features)\n        \n    \n    \n    \n    for img_id in tqdm(T_dataframe.index):\n        img = get_image2(img_id)\n        image_features = create_features(img)\n        features_list.append(image_features)\n      \n    feature_matrix = np.array(features_list)\n    return feature_matrix\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.985947Z","iopub.execute_input":"2023-10-26T03:17:56.986269Z","iopub.status.idle":"2023-10-26T03:17:56.99508Z","shell.execute_reply.started":"2023-10-26T03:17:56.986241Z","shell.execute_reply":"2023-10-26T03:17:56.993984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def add_image(T_dataframe):\n    image_list = []\n    \n    for img_id in tqdm(T_dataframe.index):\n        img = get_image2(img_id)\n        \n        image_list.append(img)\n      \n    image_matrix = np.array(image_list)\n    return image_matrix\n\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:56.996763Z","iopub.execute_input":"2023-10-26T03:17:56.997111Z","iopub.status.idle":"2023-10-26T03:17:57.006138Z","shell.execute_reply.started":"2023-10-26T03:17:56.997082Z","shell.execute_reply":"2023-10-26T03:17:57.005253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def add_image1(T_dataframe):\n    image_list = []\n    \n    for img_id in tqdm(T_dataframe.index):\n        img = get_image3(img_id)\n        \n        image_list.append(img)\n      \n    image_matrix = np.array(image_list)\n    return image_matrix\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.007556Z","iopub.execute_input":"2023-10-26T03:17:57.007901Z","iopub.status.idle":"2023-10-26T03:17:57.018473Z","shell.execute_reply.started":"2023-10-26T03:17:57.007871Z","shell.execute_reply":"2023-10-26T03:17:57.017376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_thumbnail['is_tma'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.019651Z","iopub.execute_input":"2023-10-26T03:17:57.020181Z","iopub.status.idle":"2023-10-26T03:17:57.033145Z","shell.execute_reply.started":"2023-10-26T03:17:57.020152Z","shell.execute_reply":"2023-10-26T03:17:57.031991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_thumbnail.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.035305Z","iopub.execute_input":"2023-10-26T03:17:57.035693Z","iopub.status.idle":"2023-10-26T03:17:57.047791Z","shell.execute_reply.started":"2023-10-26T03:17:57.035664Z","shell.execute_reply":"2023-10-26T03:17:57.046548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tumor = train_photodf_index[~train_photodf_index.index.isin(df_thumbnail.index)]","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.056441Z","iopub.execute_input":"2023-10-26T03:17:57.056809Z","iopub.status.idle":"2023-10-26T03:17:57.061994Z","shell.execute_reply.started":"2023-10-26T03:17:57.056777Z","shell.execute_reply":"2023-10-26T03:17:57.061122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tumor.info()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.063343Z","iopub.execute_input":"2023-10-26T03:17:57.063647Z","iopub.status.idle":"2023-10-26T03:17:57.087358Z","shell.execute_reply.started":"2023-10-26T03:17:57.063621Z","shell.execute_reply":"2023-10-26T03:17:57.086254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tumor['is_tma'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.088816Z","iopub.execute_input":"2023-10-26T03:17:57.089471Z","iopub.status.idle":"2023-10-26T03:17:57.101549Z","shell.execute_reply.started":"2023-10-26T03:17:57.089346Z","shell.execute_reply":"2023-10-26T03:17:57.100275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ntumor = df_thumbnail[df_thumbnail.index.isin(df_thumbnail.index[0:25])]","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.102861Z","iopub.execute_input":"2023-10-26T03:17:57.103415Z","iopub.status.idle":"2023-10-26T03:17:57.109856Z","shell.execute_reply.started":"2023-10-26T03:17:57.103385Z","shell.execute_reply":"2023-10-26T03:17:57.108853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ntumor200 = df_thumbnail[df_thumbnail.index.isin(df_thumbnail.index[0:200])]","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.111049Z","iopub.execute_input":"2023-10-26T03:17:57.111378Z","iopub.status.idle":"2023-10-26T03:17:57.126048Z","shell.execute_reply.started":"2023-10-26T03:17:57.111348Z","shell.execute_reply":"2023-10-26T03:17:57.125008Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ntumor","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.127609Z","iopub.execute_input":"2023-10-26T03:17:57.128644Z","iopub.status.idle":"2023-10-26T03:17:57.146892Z","shell.execute_reply.started":"2023-10-26T03:17:57.1286Z","shell.execute_reply":"2023-10-26T03:17:57.145862Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ntumor['is_tma'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.148433Z","iopub.execute_input":"2023-10-26T03:17:57.148808Z","iopub.status.idle":"2023-10-26T03:17:57.161855Z","shell.execute_reply.started":"2023-10-26T03:17:57.148777Z","shell.execute_reply":"2023-10-26T03:17:57.160851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sampleFrame = [df_tumor,df_ntumor200]\nSampleTumor = pd.concat(sampleFrame)\nSampleTumor.sort_index(axis=0, ascending=True)\nSampleTumor.info()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.163835Z","iopub.execute_input":"2023-10-26T03:17:57.164247Z","iopub.status.idle":"2023-10-26T03:17:57.180881Z","shell.execute_reply.started":"2023-10-26T03:17:57.164217Z","shell.execute_reply":"2023-10-26T03:17:57.17963Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nfeature_matrix =create_feature_matrix(df_tumor,df_thumbnail)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:17:57.181802Z","iopub.execute_input":"2023-10-26T03:17:57.182156Z","iopub.status.idle":"2023-10-26T03:20:32.723675Z","shell.execute_reply.started":"2023-10-26T03:17:57.182126Z","shell.execute_reply":"2023-10-26T03:20:32.722338Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(feature_matrix , SampleTumor.is_tma.values, test_size = .2, random_state = 1234123)\npd.Series(y_train).value_counts()\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:20:32.725583Z","iopub.execute_input":"2023-10-26T03:20:32.726052Z","iopub.status.idle":"2023-10-26T03:20:35.139994Z","shell.execute_reply.started":"2023-10-26T03:20:32.726012Z","shell.execute_reply":"2023-10-26T03:20:35.138561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Training features matrix shape:', X_train.shape)\nss = StandardScaler()\ntrain_stand = ss.fit_transform(X_train)\ntest_stand = ss.fit_transform(X_test)\nprint('Standardized training features matrix shape is:',train_stand.shape)\nprint('Standardized testing features matrix shape is:',test_stand.shape)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:20:35.141642Z","iopub.execute_input":"2023-10-26T03:20:35.142131Z","iopub.status.idle":"2023-10-26T03:20:51.042524Z","shell.execute_reply.started":"2023-10-26T03:20:35.142087Z","shell.execute_reply":"2023-10-26T03:20:51.040197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=35)\nX_train = pca.fit_transform(train_stand)\nX_test = pca.transform(test_stand)\nprint(\"training features matrix is:\", X_train.shape)\nprint(\"testing features matrix is:\",X_test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:20:51.04898Z","iopub.execute_input":"2023-10-26T03:20:51.049671Z","iopub.status.idle":"2023-10-26T03:22:03.401333Z","shell.execute_reply.started":"2023-10-26T03:20:51.049602Z","shell.execute_reply":"2023-10-26T03:22:03.399639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# define support vector classifier\nsvm = SVC(kernel='linear', probability=True, random_state=42)\n# fit model\nsvm.fit(X_train, y_train)\n# generate predictions\ny_pred = svm.predict(X_test)\n# calculate accuracy\naccuracy = accuracy_score(y_test, y_pred)\nprint('Model accuracy is: ', accuracy)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:22:03.403689Z","iopub.execute_input":"2023-10-26T03:22:03.411893Z","iopub.status.idle":"2023-10-26T03:34:19.295959Z","shell.execute_reply.started":"2023-10-26T03:22:03.411818Z","shell.execute_reply":"2023-10-26T03:34:19.294659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# predict probabilities for X_test using predict_proba\nprobabilities = svm.predict_proba(X_test)\n# select the probabilities for label 1.0\ny_proba = probabilities[:, 1]\n# calculate false positive rate and true positive rate at different thresholds\nfalse_positive_rate, true_positive_rate, thresholds = roc_curve(y_test, y_proba, pos_label=1)\n# calculate AUC\nroc_auc = auc(false_positive_rate, true_positive_rate)\nplt.title('Receiver Operating Characteristic')\n# plot the false positive rate on the x axis and the true positive rate on the y axis\nroc_plot = plt.plot(false_positive_rate,\n                    true_positive_rate,\n                    label='AUC = {:0.2f}'.format(roc_auc))\nplt.legend(loc=0)\nplt.plot([0,1], [0,1], ls='--')\nplt.ylabel('True Positive Rate')\nplt.xlabel('False Positive Rate');","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:34:19.298131Z","iopub.execute_input":"2023-10-26T03:34:19.298716Z","iopub.status.idle":"2023-10-26T03:34:19.737249Z","shell.execute_reply.started":"2023-10-26T03:34:19.29867Z","shell.execute_reply":"2023-10-26T03:34:19.735997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tumor['label'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:39:20.591624Z","iopub.execute_input":"2023-10-26T03:39:20.592355Z","iopub.status.idle":"2023-10-26T03:39:20.608653Z","shell.execute_reply.started":"2023-10-26T03:39:20.592309Z","shell.execute_reply":"2023-10-26T03:39:20.607374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_tumor_matrix = add_image(df_tumor)\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:39:28.908679Z","iopub.execute_input":"2023-10-26T03:39:28.909145Z","iopub.status.idle":"2023-10-26T03:39:45.508216Z","shell.execute_reply.started":"2023-10-26T03:39:28.909107Z","shell.execute_reply":"2023-10-26T03:39:45.506844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_ntumor_matrix = add_image1(df_ntumor)\n","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:39:45.51068Z","iopub.execute_input":"2023-10-26T03:39:45.51116Z","iopub.status.idle":"2023-10-26T03:39:53.282962Z","shell.execute_reply.started":"2023-10-26T03:39:45.511115Z","shell.execute_reply":"2023-10-26T03:39:53.281978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"im = df_tumor_matrix\nfig, axes = plt.subplots(5, 5, figsize=(7, 6), sharex=True, sharey=True)\nax = axes.ravel()\nfor i in range(0,25):\n    ax[i].imshow(im[i])\n    ax[i].set_title(\"label:{}\".format(df_tumor.iloc[i,0]))\n    \n     \n    \nfor a in ax.ravel():\n    a.axis('off')\n    \n       \nfig.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:39:53.28475Z","iopub.execute_input":"2023-10-26T03:39:53.285124Z","iopub.status.idle":"2023-10-26T03:40:02.24284Z","shell.execute_reply.started":"2023-10-26T03:39:53.285093Z","shell.execute_reply":"2023-10-26T03:40:02.241787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"imN = df_ntumor_matrix\nfig, axes = plt.subplots(5, 5, figsize=(7, 6), sharex=True, sharey=True)\nax = axes.ravel()\nfor i in range(0,25):\n    ax[i].imshow(imN[i])\n    ax[i].set_title(\"label:{}\".format(df_ntumor.iloc[i,0]))\n    \n     \n    \nfor a in ax.ravel():\n    a.axis('off')\n    \n       \nfig.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:40:02.290271Z","iopub.execute_input":"2023-10-26T03:40:02.290889Z","iopub.status.idle":"2023-10-26T03:40:10.942252Z","shell.execute_reply.started":"2023-10-26T03:40:02.290857Z","shell.execute_reply":"2023-10-26T03:40:10.941274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(0,1):\n     plt.imshow(df_tumor_matrix[i])\n     \n     plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:40:16.947734Z","iopub.execute_input":"2023-10-26T03:40:16.948234Z","iopub.status.idle":"2023-10-26T03:40:17.417359Z","shell.execute_reply.started":"2023-10-26T03:40:16.948195Z","shell.execute_reply":"2023-10-26T03:40:17.416083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(df_ntumor_matrix[0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T03:40:26.449497Z","iopub.execute_input":"2023-10-26T03:40:26.449963Z","iopub.status.idle":"2023-10-26T03:40:26.884621Z","shell.execute_reply.started":"2023-10-26T03:40:26.449901Z","shell.execute_reply":"2023-10-26T03:40:26.883235Z"},"trusted":true},"execution_count":null,"outputs":[]}]}