week4/shopping/shopping.py
def load_data(filename):
    """
    Load shopping data from a CSV file `filename` and convert into a list of
    evidence lists and a list of labels. Return a tuple (evidence, labels).

    evidence should be a list of lists, where each list contains the
    following values, in order:
        - Administrative, an integer
        - Administrative_Duration, a floating point number
        - Informational, an integer
        - Informational_Duration, a floating point number
        - ProductRelated, an integer
        - ProductRelated_Duration, a floating point number
        - BounceRates, a floating point number
        - ExitRates, a floating point number
        - PageValues, a floating point number
        - SpecialDay, a floating point number
        - Month, an index from 0 (January) to 11 (December)
        - OperatingSystems, an integer
        - Browser, an integer
        - Region, an integer
        - TrafficType, an integer
        - VisitorType, an integer 0 (not returning) or 1 (returning)
        - Weekend, an integer 0 (if false) or 1 (if true)

    labels should be the corresponding list of labels, where each label
    is 1 if Revenue is true, and 0 otherwise.
    """

    evidence = []
    labels = []

    months = {'Jan': 0,
              'Feb': 1,
              'Mar': 2,
              'Apr': 3,
              'May': 4,
              'June': 5,
              'Jul': 6,
              'Aug': 7,
              'Sep': 8,
              'Oct': 9,
              'Nov': 10,
              'Dec': 11}

    # read csv file
    csv_file = pandas.read_csv(filename)

    # prepare labels dataframe
    labels_df = csv_file['Revenue']

    # prepare evidence dataframe
    evidence_df = csv_file.drop(columns=['Revenue'])

    # replace month names with numerical values
    evidence_df = evidence_df.replace(months)

    # replace boolean with 0/1 values
    evidence_df['VisitorType'] = evidence_df['VisitorType'].apply(lambda x: 1 if x == 'Returning_Visitor' else 0)
    evidence_df['Weekend'] = evidence_df['Weekend'].apply(lambda x: 1 if x == 'True' else 0)
    labels_df = labels_df.apply(lambda x: 1 if x is True else 0)

    # convert dataframes to lists
    evidence_list = evidence_df.values.tolist()
    labels_list = labels_df.values.tolist()

    return evidence_list, labels_list

    Load shopping data from a CSV file `filename` and convert into a list of
    evidence lists and a list of labels. Return a tuple (evidence, labels).

    evidence should be a list of lists, where each list contains the
    following values, in order:
        - Administrative, an integer
        - Administrative_Duration, a floating point number
        - Informational, an integer
        - Informational_Duration, a floating point number
        - ProductRelated, an integer
        - ProductRelated_Duration, a floating point number
        - BounceRates, a floating point number
        - ExitRates, a floating point number
        - PageValues, a floating point number
        - SpecialDay, a floating point number
        - Month, an index from 0 (January) to 11 (December)
        - OperatingSystems, an integer
        - Browser, an integer
        - Region, an integer
        - TrafficType, an integer
        - VisitorType, an integer 0 (not returning) or 1 (returning)
        - Weekend, an integer 0 (if false) or 1 (if true)

    labels should be the corresponding list of labels, where each label
    is 1 if Revenue is true, and 0 otherwise.
    
Load shopping data from a CSV file `filename` and convert into a list of
evidence lists and a list of labels. Return a tuple (evidence, labels).

evidence should be a list of lists, where each list contains the
following values, in order:
Administrative, an integer
Administrative_Duration, a floating point number
Informational, an integer
Informational_Duration, a floating point number
ProductRelated, an integer
ProductRelated_Duration, a floating point number
BounceRates, a floating point number
ExitRates, a floating point number
PageValues, a floating point number
SpecialDay, a floating point number
Month, an index from 0 (January) to 11 (December)
OperatingSystems, an integer
Browser, an integer
Region, an integer
TrafficType, an integer
VisitorType, an integer 0 (not returning) or 1 (returning)
Weekend, an integer 0 (if false) or 1 (if true)

labels should be the corresponding list of labels, where each label
is 1 if Revenue is true, and 0 otherwise.
Load shopping data from a CSV file ` filename ` and convert into a list of evidence lists and a list of labels . Return a tuple ( evidence labels ) . evidence should be a list of lists where each list contains the following values in order : Administrative an integer Administrative_Duration a floating point number Informational an integer Informational_Duration a floating point number ProductRelated an integer ProductRelated_Duration a floating point number BounceRates a floating point number ExitRates a floating point number PageValues a floating point number SpecialDay a floating point number Month an index from 0 ( January ) to 11 ( December ) OperatingSystems an integer Browser an integer Region an integer TrafficType an integer VisitorType an integer 0 ( not returning ) or 1 ( returning ) Weekend an integer 0 ( if false ) or 1 ( if true ) labels should be the corresponding list of labels where each label is 1 if Revenue is true and 0 otherwise .
def load_data(filename):
    evidence = []
    labels = []
    months = {'Jan': 0,
              'Feb': 1,
              'Mar': 2,
              'Apr': 3,
              'May': 4,
              'June': 5,
              'Jul': 6,
              'Aug': 7,
              'Sep': 8,
              'Oct': 9,
              'Nov': 10,
              'Dec': 11}
    csv_file = pandas.read_csv(filename)
    labels_df = csv_file['Revenue']
    evidence_df = csv_file.drop(columns=['Revenue'])
    evidence_df = evidence_df.replace(months)
    evidence_df['VisitorType'] = evidence_df['VisitorType'].apply(lambda x: 1 if x == 'Returning_Visitor' else 0)
    evidence_df['Weekend'] = evidence_df['Weekend'].apply(lambda x: 1 if x == 'True' else 0)
    labels_df = labels_df.apply(lambda x: 1 if x is True else 0)
    evidence_list = evidence_df.values.tolist()
    labels_list = labels_df.values.tolist()
    return evidence_list, labels_list
def load_data ( filename ) : evidence = [ ] labels = [ ] months = { 'Jan' : 0 , 'Feb' : 1 , 'Mar' : 2 , 'Apr' : 3 , 'May' : 4 , 'June' : 5 , 'Jul' : 6 , 'Aug' : 7 , 'Sep' : 8 , 'Oct' : 9 , 'Nov' : 10 , 'Dec' : 11 } csv_file = pandas . read_csv ( filename ) labels_df = csv_file [ 'Revenue' ] evidence_df = csv_file . drop ( columns = [ 'Revenue' ] ) evidence_df = evidence_df . replace ( months ) evidence_df [ 'VisitorType' ] = evidence_df [ 'VisitorType' ] . apply ( lambda x : 1 if x == 'Returning_Visitor' else 0 ) evidence_df [ 'Weekend' ] = evidence_df [ 'Weekend' ] . apply ( lambda x : 1 if x == 'True' else 0 ) labels_df = labels_df . apply ( lambda x : 1 if x is True else 0 ) evidence_list = evidence_df . values . tolist ( ) labels_list = labels_df . values . tolist ( ) return evidence_list , labels_list
Load shopping data from a CSV file `filename` and convert into a list of
evidence lists and a list of labels.
Load shopping data from a CSV file ` filename ` and convert into a list of evidence lists and a list of labels .
"""
    Load shopping data from a CSV file `filename` and convert into a list of
    evidence lists and a list of labels. Return a tuple (evidence, labels).

    evidence should be a list of lists, where each list contains the
    following values, in order:
        - Administrative, an integer
        - Administrative_Duration, a floating point number
        - Informational, an integer
        - Informational_Duration, a floating point number
        - ProductRelated, an integer
        - ProductRelated_Duration, a floating point number
        - BounceRates, a floating point number
        - ExitRates, a floating point number
        - PageValues, a floating point number
        - SpecialDay, a floating point number
        - Month, an index from 0 (January) to 11 (December)
        - OperatingSystems, an integer
        - Browser, an integer
        - Region, an integer
        - TrafficType, an integer
        - VisitorType, an integer 0 (not returning) or 1 (returning)
        - Weekend, an integer 0 (if false) or 1 (if true)

    labels should be the corresponding list of labels, where each label
    is 1 if Revenue is true, and 0 otherwise.
    """ # read csv file # prepare labels dataframe # prepare evidence dataframe # replace month names with numerical values # replace boolean with 0/1 values # convert dataframes to lists
filename