本文整理匯總了Python中Classifier.Classifier.fun方法的典型用法代碼示例。如果您正苦於以下問題:Python Classifier.fun方法的具體用法?Python Classifier.fun怎麽用?Python Classifier.fun使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Classifier.Classifier
的用法示例。
在下文中一共展示了Classifier.fun方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from Classifier import Classifier [as 別名]
# 或者: from Classifier.Classifier import fun [as 別名]
class Classifier_controller:
def __init__(self):
self.tf_idf = self.create_tf_idf()
self.df_list = self.create_df_list()
self.classes = self.create_classes()
self.classifier = Classifier()
def create_tf_idf(self):
tf_idf = []
os.system("pwd")
path1 = './tutorial/data/tf_idf'
classes = os.listdir(path1)
for each_class in classes:
path2 = path1 + '/' + each_class
files = os.listdir(path2)
for each_file in files:
path3 = path2 + '/' + each_file
vector = dict()
f = open(path3)
dimes = f.readlines()
f.close()
i = 1
for dime in dimes:
if float(dime) != 0.0:
vector[i] = float(dime)
i += 1
tf_idf.append( (int(each_class), vector.items()) )
print "creating class sample_vector...\n"
print "finished..."
return tf_idf
def create_df_list(self):
df_list = []
f1 = open('./tutorial/data/df.dat')
f2 = open('./tutorial/data/attribute.dat')
df_records = f1.readlines()
att_records = f2.readlines()
f1.close()
f2.close()
i = 0
for df in df_records:
attribute = att_records[i].strip('\n')
i += 1
df_list.append((attribute, int(df)))
print "reading %s %d\n" %(attribute, int(df))
print "finished..."
return df_list
def create_classes(self):
classes = []
f = open('./tutorial/data/classes.dat')
for each in f.readlines():
classes.append(each.strip('\n'))
f.close()
return classes
def get_classes(self, text, k):
i = self.classifier.fun(text, self.df_list, len(self.tf_idf), self.tf_idf, k)
return self.classes[i]