Ejemplo n.º 1
0
    def get_association_rules(self):
        """associationRules getter helper"""
        if self.__rule is None:
            (host, port) = FrovedisServer.getServerInstance()
            ldf = rpclib.get_association_rules(host, port, self.__mid)
            excpt = rpclib.check_server_exception()
            if excpt["status"]:
                raise RuntimeError(excpt["info"])

            rules = pd.DataFrame()
            for each in ldf:
                res = fpd.DataFrame().load_dummy(each["dfptr"], \
                                       each["names"], each["types"])
                rules = merge_and_append_rules(rules, res.to_pandas_dataframe())
            self.__rule = rules.reset_index(drop=True)
        return self.__rule
Ejemplo n.º 2
0
    def freqItemsets(self):
        """freqItemsets getter"""
        if self.__fis is None:
            (host, port) = FrovedisServer.getServerInstance()
            ldf = rpclib.get_fpgrowth_fis(host, port, self.__mid)
            excpt = rpclib.check_server_exception()
            if excpt["status"]:
                raise RuntimeError(excpt["info"])

            fis = pd.DataFrame()
            for each in ldf:
                res = fpd.DataFrame().load_dummy(each["dfptr"], \
                                       each["names"], each["types"])
                fis = merge_and_append_fis(fis, res.to_pandas_dataframe())
            self.__fis = fis.reset_index(drop=True)
        return self.__fis
Ejemplo n.º 3
0
 def transform(self, data):
     """transform"""
     f_df = self.__check_input(data)
     self.generate_rules() # uses confidence provided during init()
     (host, port) = FrovedisServer.getServerInstance()
     pred = rpclib.fp_transform(host, port, f_df.get(), self.__mid)
     excpt = rpclib.check_server_exception()
     if excpt["status"]:
         raise RuntimeError(excpt["info"])
     res = fpd.DataFrame().load_dummy(pred["dfptr"], \
                                pred["names"], pred["types"])
     if len(res) >  0:
         pred = adjust_transform_output(
                                 res.to_pandas(), 
                                 f_df.to_pandas())
     else:
         res = pd.DataFrame({'trans_id':[], 'consequent':[]})
         pred = adjust_transform_output(
                                 res, 
                                 f_df.to_pandas())
     return pred
Ejemplo n.º 4
0
 def __convert_iterable(self, data):
     """
     converts an iterable to frovedis DataFrame
     """
     tid = []
     item = []
     cur_id = 1
     #print("### iterable data: ")
     #print(data)
     if self.encode_string_input:
         data = self.__encode_input(data)
         #print("### encoded iterable data: ")
         #print(data)
     for trans in data: # for each transaction in data
         for trans_it in trans: # for each item in each transaction
             tid.append(cur_id)
             item.append(trans_it)
         cur_id = cur_id + 1
     df_t = pd.DataFrame({'trans_id': tid, 'item': item}, \
                         columns=['trans_id', 'item'])
     #print("### converted pandas dataframe: ")
     #print(df_t)
     return fpd.DataFrame(df_t)
Ejemplo n.º 5
0
peopleDF = {
    'Ename': ['Michael', 'Andy', 'Tanaka', 'Raul', 'Yuta'],
    'Age': [29, 30, 27, 19, 31],
    'Country': ['USA', 'England', 'Japan', 'France', 'Japan'],
    'isMale': [False, False, False, False, True]
}

countryDF = {
    'Ccode': [1, 2, 3, 4],
    'Country': ['USA', 'England', 'Japan', 'France']
}

pdf1 = pd.DataFrame(peopleDF)
pdf2 = pd.DataFrame(countryDF)
fdf1 = fdf.DataFrame(pdf1)
fdf2 = fdf.DataFrame(pdf2)

# displaying created frovedis dataframes
fdf1.show()
fdf2.show()

# select demo
fdf1["Ename"].show()  # single column
fdf1[["Ename", "Age"]].show()  # multiple column

# filter demo
fdf1[fdf1.Age > 19].show()
fdf1[(fdf1.Age > 19) & (fdf1.Country == 'Japan')].show()  # AND Demo
fdf1[~((fdf1.Age > 19) & (fdf1.Country == 'Japan'))].show()  # NOT Demo