def loadDemoTables(): ''' Load the tables used in the Demo, if they don't exist. ''' dbconn = DBConnect() conn_dict = dbconn.getConnectionString() load_tbl_stmt = '''psql -h {hostname} -p {port} -U {username} -d {database} -f ''' load_tbl_stmt = load_tbl_stmt.format(username=conn_dict['username'], hostname=conn_dict['hostname'], database=conn_dict['database'], port=conn_dict['port']) this_dir = os.path.dirname(os.path.abspath(__file__)) for fl in os.listdir(os.path.join(this_dir, 'data/')): full_path = os.path.join(os.path.join(this_dir, 'data'), fl) if (fl.endswith('.sql')): #If the demo table does not exists in the database already, create it using the provided sql files if (not __isTableExists__(fl[:-len('.sql')], dbconn)): logging.info('cmd:{0}'.format(load_tbl_stmt + ' ' + full_path)) cmd = load_tbl_stmt + ' ' + full_path os.system(cmd) logging.info('Loading demo tables complete')
def loadDemoTables(): ''' Load the tables used in the Demo, if they don't exist. ''' dbconn = DBConnect() conn_dict = dbconn.getConnectionString() load_tbl_stmt = '''psql -h {hostname} -p {port} -U {username} -d {database} -f ''' load_tbl_stmt = load_tbl_stmt.format( username=conn_dict['username'], hostname=conn_dict['hostname'], database=conn_dict['database'], port=conn_dict['port'] ) this_dir = os.path.dirname(os.path.abspath(__file__)) for fl in os.listdir(os.path.join(this_dir,'data/')): full_path = os.path.join(os.path.join(this_dir,'data'),fl) if(fl.endswith('.sql')): #If the demo table does not exists in the database already, create it using the provided sql files if(not __isTableExists__(fl[:-len('.sql')],dbconn)): logging.info('cmd:{0}'.format(load_tbl_stmt+' '+full_path)) cmd = load_tbl_stmt+ ' '+full_path os.system(cmd) logging.info('Loading demo tables complete')
def conn_test(): ''' Test the connection by displaying rows from a table ''' conn = DBConnect() cursor = conn.getCursor(True) cursor.executeQuery('select * from wine_training_set') conn.printTable(cursor)
def pyMADlibDemo(): ''' Demonstrate building Linear Regression and Logistic Regression Models using MADlib ''' conn = DBConnect(madlib_schema='madlib_v05') #1) Linear Regression linearRegressionDemo(conn) #2) Logistic Regression logisticRegDemo(conn) #3) SVM Regression svmDemo(conn) #4) KMeans kmeansDemo(conn) #5) PLDA pldaDemo(conn)
drop table if exists {output_table} cascade; create table {output_table} as ( select array[{list_of_indep_cols}] as {indep_cols_arr_name} from {table_name} ); ''' convert_to_arr_stmt = convert_to_arr_stmt.format(**data_dict) conn.executeQuery(convert_to_arr_stmt) return output_table, indep_cols_arr_name if (__name__ == '__main__'): from pymadlib import DBConnect conn = DBConnect() output_table, indep, dep, cols_distinct_vals = pivotCategoricalColumns( conn, 'cuse_dat', ['1', 'age', 'education', 'wantsmore', 'notusing'], 'yesusing') print 'output table :', output_table print 'output independent columns :', indep print 'dependent col :', dep #Verify if the input has all numeric columns, the input table is returned unchanged. output_table, indep, dep, cols_distinct_vals = pivotCategoricalColumns( conn, 'wine_training_set', ['1', 'alcohol', 'proline', 'hue', 'color_intensity', 'flavanoids'], 'quality') print 'output table :', output_table print 'output independent columns :', indep print 'dependent col :', dep