Example #1
0
def logisticRegDemo(conn):
    '''
       Demonstrate Logistic Regression
    '''    
    
    #1) Logistic Regression with Numeric Variables Alone
    log_reg = LogisticRegression(conn)
    #Train Model
    mdl_dict, mdl_params = log_reg.train('public.wine_bool_training_set','indep','quality_label')
    #Show Model Parameters
    mdl_params.head()
    #2) Logistic Regression Prediction 
    predictions = log_reg.predict('wine_bool_test_set','',None)
    predictions.head()

    #Display ROC Curve
    actual = predictions.get('quality_label')
    predicted = predictions.get('prediction')
    ROCPlot('ROC curve Logistic Reg. on Continuous Features ',['Logistic Regression'],actual,predicted) 
    
    # 2) Logistic Regression with mixture of numeric and categorical columns     
    mdl_dict, mdl_params = log_reg.train('public.auto_mpg_bool_train',['1','height','width','length','highway_mpg',
                                         'engine_size','make','fuel_type','fuel_system'],
                                         'is_expensive'
                           )
    predictions = log_reg.predict('auto_mpg_bool_test','is_expensive',None)
    cols = conn.fetchColumns(cursor,['is_expensive','prediction'])
    actual = predictions.get('is_expensive')
    predicted = predictions.get('prediction') 
    ROCPlot('ROC curve Logistic Reg. including categorical data',['Logistic Regression'],actual,predicted)  
Example #2
0
def logisticRegDemo(conn):
    '''
       Demonstrate Logistic Regression
    '''    
    
    # a) Logistic Regression with numeric attributes
    log_reg = LogisticRegression(conn)
    log_reg.train('public.wine_bool_training_set','indep','quality_label')
    cursor = log_reg.predict('public.wine_bool_test_set','',0.5)
    conn.printTable(cursor,['id','quality_label','prediction'])
            
    # b) ROC curve for Logistic Regression using numeric features alone, 
    # Note: Here threshold is set to None, to be able to plot ROC curve    
    cursor = log_reg.predict('wine_bool_test_set','',None)
    cols = conn.fetchColumns(cursor,['quality_label','prediction'])
    actual = cols['quality_label']
    predicted = cols['prediction']
    #show ROC curve
    ROCPlot('ROC curve Logistic Reg. on Continuous Features ',['Logistic Regression'],actual,predicted)
    
    # c) Logistic Regression with mixture of numeric and categorical columns     
    log_reg.train('public.auto_mpg_bool_train',['1','height','width','length','highway_mpg','engine_size','make','fuel_type','fuel_system'],'is_expensive')
    cursor = log_reg.predict('auto_mpg_bool_test','is_expensive',None)
    cols = conn.fetchColumns(cursor,['is_expensive','prediction'])
    actual = cols['is_expensive']
    predicted = cols['prediction']  
    ROCPlot('ROC curve Logistic Reg. including categorical data',['Logistic Regression'],actual,predicted)  
Example #3
0
def logisticRegDemo(conn):
    '''
       Demonstrate Logistic Regression
    '''

    #1) Logistic Regression with Numeric Variables Alone
    log_reg = LogisticRegression(conn)
    #Train Model
    mdl_dict, mdl_params = log_reg.train('public.wine_bool_training_set',
                                         'indep', 'quality_label')
    #Show Model Parameters
    mdl_params.head()
    #2) Logistic Regression Prediction
    predictions = log_reg.predict('wine_bool_test_set', '', None)
    predictions.head()

    #Display ROC Curve
    actual = predictions.get('quality_label')
    predicted = predictions.get('prediction')
    ROCPlot('ROC curve Logistic Reg. on Continuous Features ',
            ['Logistic Regression'], actual, predicted)

    # 2) Logistic Regression with mixture of numeric and categorical columns
    mdl_dict, mdl_params = log_reg.train('public.auto_mpg_bool_train', [
        '1', 'height', 'width', 'length', 'highway_mpg', 'engine_size', 'make',
        'fuel_type', 'fuel_system'
    ], 'is_expensive')
    predictions = log_reg.predict('auto_mpg_bool_test', 'is_expensive', None)
    cols = conn.fetchColumns(cursor, ['is_expensive', 'prediction'])
    actual = predictions.get('is_expensive')
    predicted = predictions.get('prediction')
    ROCPlot('ROC curve Logistic Reg. including categorical data',
            ['Logistic Regression'], actual, predicted)