This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas.io.parsers import ParserError | |
# create a list to store the dataframes | |
dataframe_list = [] | |
# iterate through the folders 1 to 34 | |
for folder in range(1, 35): | |
# create two boolean variables for both kind of exceptions. | |
parse_error = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pd.read_csv('dataset/32/region_32.csv') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a list to store the dataframes | |
dataframe_list = [] | |
# iterate through folder 1 to 34 | |
for folder in range(1, 35): | |
# try we are able to read the file | |
try : | |
### notice that for folder i, we have file name "region_i" | |
### create the file name | |
file_name = 'region_' + str(folder) + '.csv' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for folder in range(1, 35): | |
file_name = 'region_' + str(folder) + '.csv' | |
data = pd.read_csv('dataset/'+ str(folder) +'/' +file_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for directory in glob.glob('dataset/*'): | |
for files in glob.glob(directory + '/*'): | |
print(files) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list all the files in the folder | |
for directory in glob.glob('dataset/*'): | |
print(directory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import the required libraries | |
import glob | |
import pandas as pd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_gender_encoded, validate_gender_encoded, test_gender_encoded = transform_data(train_gender, | |
validate_gender, | |
impute_gender, | |
'gender', | |
{ | |
'type' : { 'BinaryEncoding' : ['city','branch_code','age_bucket'], | |
'OneHotEncoding' : ['occupation','dependents'] | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transform_data(_data,_validate,_test,_target,encoding) : | |
if 'BinaryEncoding' in encoding['type'].keys(): | |
ce_OHE = ce.BinaryEncoder(cols=encoding['type']['BinaryEncoding']) | |
ce_OHE.fit(_data) | |
_data = ce_OHE.transform(_data) | |
_test = ce_OHE.transform(_test) | |
_validate = ce_OHE.transform(_validate) | |
if 'TargetEncoding' in encoding['type'].keys(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the prediction array | |
predictions = predictions['predictions'] | |
# print the actual image and the predicted result | |
for i, prediction in enumerate(predictions): | |
print("Prediction: ",np.argmax(prediction)) | |
show(i,test_images[i]) |