def prediction(inputfile, model): #read in data try: data = pd.read_csv(inputfile, header=None) print("Data loaded") except: print("Dataset could not be loaded. Is the dataset missing?") data.columns = [ 'AAGE', 'ACLSWKR', 'ADTIND', 'ADTOCC', 'AHGA', 'AHRSPAY', 'AHSCOL', 'AMARITL', 'AMJIND', 'AMJOCC', 'ARACE', 'AREORGN', 'ASEX', 'AUNMEM', 'AUNTYPE', 'AWKSTAT', 'CAPGAIN', 'CAPLOSS', 'DIVVAL', 'FILESTAT', 'GRINREG', 'GRINST', 'HHDFMX', 'HHDREL', 'MIGMTR1', 'MIGMTR3', 'MIGMTR4', 'MIGSAME', 'MIGSUN', 'NOEMP', 'PARENT', 'PEFNTVTY', 'PEMNTVTY', 'PENATVTY', 'PRCITSHP', 'SEOTR', 'VETQVA', 'VETYN', 'WKSWORK', 'YEAR' ] # preprocess data data = preprocess(data) # load model file try: loaded_model = pickle.load(open(model, 'rb')) print("Model loaded") except: print("Model could not be loaded. Is the model missing?") # predict run result = loaded_model.predict(data) # show result print(result)
def prediction(inputfile, model): #read in data try: data = pd.read_csv(inputfile, header=None) print("Data loaded") except: print("Dataset could not be loaded. Is the dataset missing?") data.columns = [ 'AAGE', 'ACLSWKR', 'ADTIND', 'ADTOCC', 'AHGA', 'AHRSPAY', 'AHSCOL', 'AMARITL', 'AMJIND', 'AMJOCC', 'ARACE', 'AREORGN', 'ASEX', 'AUNMEM', 'AUNTYPE', 'AWKSTAT', 'CAPGAIN', 'CAPLOSS', 'DIVVAL', 'FILESTAT', 'GRINREG', 'GRINST', 'HHDFMX', 'HHDREL', 'MARSUPWT', 'MIGMTR1', 'MIGMTR3', 'MIGMTR4', 'MIGSAME', 'MIGSUN', 'NOEMP', 'PARENT', 'PEFNTVTY', 'PEMNTVTY', 'PENATVTY', 'PRCITSHP', 'SEOTR', 'VETQVA', 'VETYN', 'WKSWORK', 'YEAR', 'TARGET' ] # features for segementation model filterCol = [ 'AAGE', 'AHGA', 'ASEX', 'CAPGAIN', 'CAPLOSS', 'DIVVAL', 'NOEMP', 'WKSWORK' ] # preprocess data data = preprocess(data) # filtered data fdata = data[filterCol] # predict data pdata = fdata # apply PCA by fitting the predict data with only two dimensions pca = PCA(n_components=2) pca.fit(pdata) reduced_data = pca.transform(pdata) reduced_data = pd.DataFrame(reduced_data, columns=['Dimension 1', 'Dimension 2']) # load model file try: loaded_model = pickle.load(open(model, 'rb')) print("Model loaded") except: print("Model could not be loaded. Is the model missing?") # predict run result = loaded_model.predict(reduced_data) # show result print(result)
import importlib import func import numpy as np import pandas as pd df_101191 = pd.read_excel("data/191_BWSC101 Release Log Form.xlsx") df_101592 = pd.read_excel("data/592_BWSC101 Release Log Form.xlsx") df_101607 = pd.read_excel("data/607_BWSC101 Release Log Form.xlsx") df_101191["RTN"] = df_101191.apply(func.completeRTN, axis=1) df_101592["RTN"] = df_101592.apply(func.completeRTN, axis=1) df_101607["RTN"] = df_101607.apply(func.completeRTN, axis=1) func.preprocess(df_101607, "101607proc.xlsx", "101607") print(df_101607.shape) func.preprocess(df_101592, "101592proc.xlsx", "101592") print(df_101592.shape) func.preprocess(df_101191, "101191proc.xlsx", "101191") print(df_101191.shape) df_101 = df_101191.append(df_101592) df_101 = df_101.append(df_101607) df_101 = df_101[(df_101["A3A"] == 1) | (df_101["A2A"] == 1)] print(df_101.shape) # TCLass tclass = pd.read_excel( 'data/TClass Phase Action Dates All RTNs mgf A 04-10-2018.xlsm', sheetname="All")
print('Implement Spectral & Spatial Joint Network!') else: raise NotImplementedError ############# load dataset(indian_pines & pavia_univ...)###################### a = load() All_data, labeled_data, rows_num, categories, r, c, FLAG = a.load_data( flag=args.dataset) print('Data has been loaded successfully!') ##################### Demision reduction & normlization ###################### a = preprocess(args.dr_method, args.dr_num) #PCA & ICA Alldata_DR = a.Dim_reduction(All_data) print('Dimension reduction successfully!') a = product(c, FLAG) All_data_norm = a.normlization(All_data[:, 1:-1], args.mi, args.ma) #spec Alldata_DR = a.normlization(Alldata_DR, args.mi, args.ma) #spat image_data3D_DR = Alldata_DR.reshape(r, c, -1) print('Image normlization successfully!')
print( "Dataset could not be loaded. Is the dataset missing? Please use -i inputfile" ) data.columns = [ 'AAGE', 'ACLSWKR', 'ADTIND', 'ADTOCC', 'AHGA', 'AHRSPAY', 'AHSCOL', 'AMARITL', 'AMJIND', 'AMJOCC', 'ARACE', 'AREORGN', 'ASEX', 'AUNMEM', 'AUNTYPE', 'AWKSTAT', 'CAPGAIN', 'CAPLOSS', 'DIVVAL', 'FILESTAT', 'GRINREG', 'GRINST', 'HHDFMX', 'HHDREL', 'MARSUPWT', 'MIGMTR1', 'MIGMTR3', 'MIGMTR4', 'MIGSAME', 'MIGSUN', 'NOEMP', 'PARENT', 'PEFNTVTY', 'PEMNTVTY', 'PENATVTY', 'PRCITSHP', 'SEOTR', 'VETQVA', 'VETYN', 'WKSWORK', 'YEAR', 'TARGET' ] # preprocess data data = preprocess(data) # balance data by SMOTE X, y, data = handle_imbalanced_data(data) # drop instance weight from data instance_weight = data.MARSUPWT data = data.drop('MARSUPWT', axis=1) # drop label from data X = data.drop('TARGET', axis=1) # feature selection ''' X : features y : labels data : preprocessed data