Esempio n. 1
0
 def gather_all_inputs(self, input_dict):
     col_order = [key for key in input_dict.keys()]
     for key, data in input_dict.items():
         input_dict.update({key: [data]})
     data = DataFrame(input_dict, col_order)
     data.append_pairwise_interactions()
     data.append_columns({'constant': [1]})
     self.current_input = data
     return data.data_dict
data_dict = {
    'beef': [0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5],
    'pb': [0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5],
    'condiments': [[], ['mayo'], ['jelly'], ['mayo', 'jelly'], [], ['mayo'],
                   ['jelly'], ['mayo', 'jelly'], [], ['mayo'], ['jelly'],
                   ['mayo', 'jelly'], [], ['mayo'], ['jelly'],
                   ['mayo', 'jelly']],
    'rating': [1, 1, 4, 0, 4, 8, 1, 0, 5, 0, 9, 0, 0, 0, 0, 0]
}

df = DataFrame(data_dict, column_order=['beef', 'pb', 'condiments'])
df = df.create_dummy_variables()
df = df.append_pairwise_interactions()
df = df.append_columns({
    'constant': [1 for _ in range(len(data_dict['rating']))],
    'rating': data_dict['rating']
})

df = df.apply('rating', lambda x: 0.1 if x == 0 else x)

regressor = LogisticRegressor(df, prediction_column='rating', max_val=10)

assert regressor.multipliers == [
    -0.039, -0.0205, 1.7483, -0.3978, 0.1497, -0.7485, 0.4682, 0.3296, -0.5288,
    2.6441, 1.0125
], 'Wong multipliers'

assert regressor.predict({
    'beef': 5,
    'pb': 5,
    'mayo': 1,
data_dict = {
    'beef': [0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5],
    'pb': [0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5],
    'condiments': [[], ['mayo'], ['jelly'], ['mayo', 'jelly'], [], ['mayo'],
                   ['jelly'], ['mayo', 'jelly'], [], ['mayo'], ['jelly'],
                   ['mayo', 'jelly'], [], ['mayo'], ['jelly'],
                   ['mayo', 'jelly']],
    'rating': [1, 1, 4, 0, 4, 8, 1, 0, 5, 0, 9, 0, 0, 0, 0, 0]
}
df = DataFrame(data_dict, column_order=['beef', 'pb', 'condiments'])

df = df.create_dummy_variables()
df = df.append_pairwise_interactions()
df = df.append_columns({
    'constant': [1 for _ in range(len(data_dict['beef']))],
    'rating': [1, 1, 4, 0, 4, 8, 1, 0, 5, 0, 9, 0, 0, 0, 0, 0]
})
df = df.apply('rating', lambda x: 0.1 if x == 0 else x)
regressor = LogisticRegressor(df, prediction_column='rating', max_value=10)

# print("\n Testing multipliers")
# assert regressor.multipliers == {
#     'beef': -0.03900793,
#     'pb': -0.02047944,
#     'mayo': 1.74825378,
#     'jelly': -0.39777219,
#     'beef_pb': 0.14970983,
#     'beef_mayo': -0.74854916,
#     'beef_jelly': 0.46821312,
#     'pb_mayo': 0.32958369,
#     'pb_jelly': -0.5288267,
Esempio n. 4
0
data_dict = {
    'percentile': [95, 95, 92, 85, 80, 85, 95, 87, 99, 95],
    'ACT': [33, 34, 35, 30, 36, 29, 36, 31, 36, 32],
    'extracurricular': [1, 0, 1, 1, 1, 1, 1, 1, 0, 0],
    'acceptance':
    [0.999, 0.001, 0.999, 0.001, 0.999, 0.001, 0.999, 0.001, 0.999, 0.001]
}
df = DataFrame(data_dict,
               column_order=['percentile', 'ACT', 'extracurricular'])
# print(df.ordered_dict)
df = df.append_pairwise_interactions()
# print(df.ordered_dict)
df = df.append_columns({
    'constant': [1 for _ in range(len(data_dict['percentile']))],
    'acceptance':
    [0.999, 0.001, 0.999, 0.001, 0.999, 0.001, 0.999, 0.001, 0.999, 0.001]
})
# print(df.ordered_dict)
df = df.apply('acceptance', lambda x: 0.1 if x == 0 else x)
# print(df.ordered_dict)

regressor = LogisticRegressor(df, prediction_column='acceptance', max_value=1)
print(regressor.coefficients)
print(
    "Martha: " +
    str(regressor.predict({
        'percentile': 95,
        'ACT': 33,
        'extracurricular': 1
    })))