def save_to_file(self, dict, name): file_path = Extension.get_data_dir(self.config) / ("%s.pkl" % name) try: with file_path.open("wb") as f: pickle.dump(dict, f, pickle.HIGHEST_PROTOCOL) pickle.close() except Exception: return False
def save_to_file(self, dict, name): file_path = Path(self.config["iris"]["data_dir"]) / ("%s.pkl" % name) try: with file_path.open("wb") as f: pickle.dump(dict, f, pickle.HIGHEST_PROTOCOL) pickle.close() except Exception: return False
def train(trainingDataFolder, featureFile, labelFile): y_train = genfromtxt(labelFile) y_train1 = np.zeros(y_train.shape, dtype=np.int32) for items in range(y_train.shape[0]): y_train1[items] = y_train[items] x_train1 = genfromtxt(featureFile, delimiter=',') # Create a svm Classifier # clf = svm.SVC(kernel='linear') # Linear Kernel clf = svm.SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0, decision_function_shape='ovr', degree=1, gamma='auto', kernel='linear', max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.0001, verbose=False) X_train, X_test, y_train, y_test = train_test_split(x_train1, y_train1, test_size=0.3, random_state=109) clf.fit(x_train1, y_train1) y_pred = clf.predict(X_test) accuracy = accuracy_score(y_test, y_pred) y_pred1 = clf.predict(x_train1) accuracy = accuracy_score(y_train1, y_pred1) featuresTestfile = trainingDataFolder + '/featuresTest.csv' x_test = genfromtxt(featuresTestfile, delimiter=',') y_pred = np.zeros(x_test.shape[0], dtype=np.int32) # Predict the response for test dataset y_pred = clf.predict(x_test) # Save model file modelFile = trainingDataFolder + '/SVMModel.bin' pickle.dump(clf, open(modelFile, 'wb')) pickle.close() modelFile1 = trainingDataFolder + '/SVMModel1.bin' joblib.dump(clf, open(modelFile1, 'wb')) return modelFile1
""" #call functions of the file and this file only for ruleGeneration #the use of a hash table superdict which was created in gen_powerset.py which has the support of all frequent candidates has been made to find support in O(1) time. #we also use the fact that all subsets of a frequent candidate shall be frequent to avoid hitting the data set import pickle import copy pkl_file = open("../pkl_files/superdict.pkl","rb") superdict = pickle.load(pkl_file) item = [] pkl_file.close() pkl_file = open("../pkl_files/redundant_item.pkl","rb") redundant_item = pickle.load(pkl_file) pickle.close() pkl_file = open("../pkl_files/hash_table.pkl","rb") hash_table = pickle.load(pkl_file) pkl_file.close() #it is a recurssive functions which takes in lv1 rules as input and generate rules for rest of generations def generateAllRules(x,y,used,item): x = list(x) y = list(y) if len(x) > 1: inum = 0 for i in x: x_made = [] x_made = x[:] y_made = y[:] y_made.append(x[inum]) y_made.sort()
def createMonthlyDataFile(self): path = "/home/prashant/pythonGeneratedFiles/" year = "2015" powerIndex = 10 for m in range(1, 13): totalEnergy = 0 temp = datetime(1900, 1, 1, 0, 0, 0) duration = datetime(1900, 1, 1, 0, 0, 0) peak = 0 mFile = year if m < 10: mFile = mFile + "-0" + str(m) else: mFile = mFile + "-" + str(m) fm = open(mFile + ".csv", "w") fm.write("Total energy,Peak,Duration\n") print "Creating Month :", m, " File..............." if m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12: dateMax = 31 elif m == 2: dateMax = 28 else: dateMax = 30 for d in range(1, dateMax + 1): fileName = year if m < 10: fileName = fileName + "-0" + str(m) + "-" else: fileName = fileName + "-" + str(m) + "-" if d < 10: fileName = fileName + "0" + str(d) else: fileName = fileName + str(d) if os.path.exists(path + fileName + ".csv"): fp = open(path + fileName + ".csv", "r") print fp.readline().split(",") startTime = datetime.strptime(fp.readline().split(",")[0], "%H:%M") for fileData in fp: singleData = fileData.split(",") if int(singleData[powerIndex]) > peak: peak = singleData[powerIndex] endTime = datetime.strptime(singleData[0], "%H:%M") temp = endTime - startTime duration = duration + temp fp.close() totalEnergy = totalEnergy + int(singleData[11]) print "Month :" + str(m) + "-" + year print "Total Energy=", totalEnergy print "Duration :", duration print "Peak :", peak fm.write(str(totalEnergy)) fm.write(",") fm.write(str(peak)) fm.write(",") fm.write(str(duration)) fm.close()