mirror of
https://github.com/RustyRaptor/keras-corn.git
synced 2026-12-03 15:15:19 -07:00
15 KiB
15 KiB
In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import io
import time
import json
from io import StringIO
import os
import re
import shutilIn [2]:
data = pd.read_csv('./input/annotations_handheld.csv', header = None)
# specify columns extracted from wbdc.names
data.columns = ["image","x1","y1","x2","y2","user","day","month","year","hour","minute"]
# save the data
data.to_csv("data.csv", sep=',', index=False)
# print the shape of the data file
print(data.shape)
# show the top few rows
display(data.head())
# describe the data object
display(data.describe())
# Time to clean the data
# Columns to remove that aren't needed for training
# We keep image to use as an identifier and we keep x1 temporarily to determine
# if the image has a lesion
to_drop = ["user", "day", "month", "year", "hour", "minute", "y1", "x2", "y2"]
# we will edit the data in a new variable
new_data = data
# drop the first row because it is just a repeat of the column labels and doesn't serve us.
new_data = new_data.drop(0)
# iterate through the list of items to drop and drop them from new_data
for i in to_drop:
new_data = new_data.drop(i, axis=1)
print("removed: " + i)
# show the data to make sure it worked
display(new_data.head())
# now we will create a list that coresponds to the x1 column
# a value equal to 0 has no lesions while a value greater means there is a lesion
has_lesion = []
for item in new_data["x1"]:
if int(item) == 0:
has_lesion.append("False")
elif int(item) > 0:
has_lesion.append("True")
else:
print("ERROR: Value is less than 0 or invalid") # If the value isn't 0 or greater something is off in the data
# print(bool_column)
# Now we create a column and set it's value to the list
new_data["has_lesion"] = pd.Series(has_lesion, index=new_data.index)
new_data = new_data.drop_duplicates("image")
# display the new_data to ensure the new column is there and has the correct values
display(new_data.head())
csv_buffer = StringIO()
new_data.to_csv(csv_buffer)
with open ('fixed.csv', 'w') as fd:
csv_buffer.seek (0)
shutil.copyfileobj (csv_buffer, fd)(7700, 11)
| image | x1 | y1 | x2 | y2 | user | day | month | year | hour | minute | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | image | x1 | y1 | x2 | y2 | user | day | month | year | hour | minute |
| 1 | DSC00025.JPG | 1864 | 2064 | 2864 | 1648 | Tyr | 26 | 5 | 2016 | 16 | 48 |
| 2 | DSC00026.JPG | 2872 | 1416 | 3152 | 2016 | Tyr | 26 | 5 | 2016 | 16 | 48 |
| 3 | DSC00027.JPG | 0 | 0 | 0 | 0 | Tyr | 5 | 10 | 2015 | 17 | 0 |
| 4 | DSC00028.JPG | 3248 | 1540 | 3572 | 2048 | Tyr | 26 | 5 | 2016 | 16 | 48 |
| image | x1 | y1 | x2 | y2 | user | day | month | year | hour | minute | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| count | 7700 | 7700 | 7700 | 7700 | 7700 | 7700 | 7700 | 7700 | 7700 | 7700 | 7700 |
| unique | 1788 | 1446 | 994 | 1460 | 997 | 2 | 4 | 4 | 3 | 3 | 11 |
| top | DSC06550.JPG | 0 | 0 | 0 | 0 | Tyr | 4 | 4 | 2016 | 17 | 0 |
| freq | 53 | 769 | 773 | 784 | 794 | 7699 | 5558 | 5558 | 6931 | 4238 | 1918 |
removed: user removed: day removed: month removed: year removed: hour removed: minute removed: y1 removed: x2 removed: y2
| image | x1 | |
|---|---|---|
| 1 | DSC00025.JPG | 1864 |
| 2 | DSC00026.JPG | 2872 |
| 3 | DSC00027.JPG | 0 |
| 4 | DSC00028.JPG | 3248 |
| 5 | DSC00028.JPG | 3444 |
| image | x1 | has_lesion | |
|---|---|---|---|
| 1 | DSC00025.JPG | 1864 | True |
| 2 | DSC00026.JPG | 2872 | True |
| 3 | DSC00027.JPG | 0 | False |
| 4 | DSC00028.JPG | 3248 | True |
| 6 | DSC00029.JPG | 0 | False |
In [ ]: