<jupyter_start><jupyter_text>Data preparation  1.First, we convert the DICOM file to jpg file for data input.<jupyter_code>import os
import matplotlib.pyplot as plt
import pydicom
import png
from pydicom.data import get_testdata_files
import scipy.misc

folder = '../all/stage_2_train_images'
filenames = os.listdir(folder)

# in_path = '0a0f91dc-6015-4342-b809-d19610854a21.dcm'
# out_path = '0a0f91dc-6015-4342-b809-d19610854a21.jpg'

for name in filenames:
    ds = pydicom.read_file(folder+"/"+name)  #read dcm file
    img = ds.pixel_array  # read image array information
    scipy.misc.imsave("input_jpg/"+name+".jpg",img) #output jpg file<jupyter_output>/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:17: DeprecationWarning: `imsave` is deprecated!
`imsave` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imwrite`` instead.<jupyter_text>EDA  Below shows the csv file containg id, parameters, labels class and file directory.<jupyter_code>import pandas as pd

file = pd.read_csv('./stage_2_train_labels.csv')
file.head(9)<jupyter_output><empty_output><jupyter_text>Statistics about parameters<jupyter_code>file.describe()
#Number of pneumonia positive and negative
pneumonia_positive_num=file.Target.value_counts()
print(pneumonia_positive_num)
#Number of pneumonia positive(1), negetive(0) and negative not normal(2)
pneumonia_positive_num=file.AdvTarget.value_counts()
print(pneumonia_positive_num)<jupyter_output>2    11821
1     9555
0     8851
Name: AdvTarget, dtype: int64<jupyter_text>Create boundary box' area variable for training setand plot the distribution<jupyter_code>import numpy as np
file['area']=file['width']*file['height']
file.head()
from matplotlib import pyplot as plt
plt.hist(file['area'].dropna(), bins=50, color='steelblue',density=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10917979359043997, 'fraction_numerical': 0.047800108636610536, 'mean_word_length': 6.518367346938776, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '77102', 'license': 'MIT', 'n_tokens_mistral': 722, 'n_tokens_neox': 663, 'n_words': 148, 'path': 'Final_Project/Data_Preparation_and_EDA.ipynb', 'repo_name': 'baoj39532/Data_Science_Final', 'size': '1841'}