def main(): try: # user input for the path of the dataset filedir = input("enter the complete directory path ") filepath = input("enter the folder name") # load the files all_files = os.listdir(filedir) freq_max1, freq_max2, freq_max3, freq_max4, freq_max5 = cal_max_freq( all_files, filepath) except IOError: print( "you have entered either the wrong data directory path or filepath" ) # load the model filename = "kmeanModel.npy" model = np.load(filename).item() # checking the iteration if (filepath == "1st_test/"): rhigh = 8 else: rhigh = 4 testlabels = [] for i in range(0, rhigh): print("checking for the bearing", i + 1) result = pd.DataFrame() result['freq_max1'] = list((np.array(freq_max1))[:, i]) result['freq_max2'] = list((np.array(freq_max2))[:, i]) result['freq_max3'] = list((np.array(freq_max3))[:, i]) result['freq_max4'] = list((np.array(freq_max4))[:, i]) result['freq_max5'] = list((np.array(freq_max5))[:, i]) X = result[[ "freq_max1", "freq_max2", "freq_max3", "freq_max4", "freq_max5" ]] label = model.predict(X) labelfive = list(label[-100:]).count(5) labelsix = list(label[-100:]).count(6) labelseven = list(label[-100:]).count(7) totalfailur = labelfive + labelsix + labelseven #+labelfour ratio = (totalfailur / 100) * 100 if (ratio >= 25): print("bearing is suspected to fail") else: print("bearing is working in normal condition") testlabels.append(label[-100:]) # ploting the labels plotlabels(testlabels) plt.show()
def main(): try: # user input for the path of the dataset filedir = input("enter the complete directory path ") filepath = input("enter the folder name") #load the files all_files = os.listdir(filedir) freq_max1,freq_max2,freq_max3,freq_max4,freq_max5 = cal_max_freq(all_files,filepath) except IOError: print("you have entered either the wrong data directory path or filepath") #load the model filename = "GMM_all.npy" model = np.load(filename).item() #checking the iteration if (filepath == "1st_test/"): rhigh = 8 else: rhigh = 4 print("for the testset", filepath) prediction_last_100 = [] for i in range(0,rhigh): #making the dataframe X = create_dataframe(freq_max1,freq_max2,freq_max3,freq_max4,freq_max5,i) print("checking for the bearing",i+1) label = model.predict(X) check_two = list(label[-100:]).count(2) ratio = (check_two/100)*100 print("prediction",ratio) if(ratio >= 50): print("bearing is suspected to fail") else: print("bearing is working in normal condition") prediction_last_100.append(label[-100:]) plotlabels(prediction_last_100) plt.show()
# reading all the files from the testset1, and testset2 filedir_testset1 = "Bearing Dataset/1st_test/" #input("enter the complete directory path for the testset1 ")"" filedir_testset2 = "Bearing Dataset/2nd_test/" #input("enter the complete directory path for the testset2 ") all_files_testset1 = os.listdir(filedir_testset1) all_files_testset2 = os.listdir(filedir_testset2) # relative path of the dataset, after the current working directory path_testset2 = "Bearing Dataset/2nd_test/" path_testset1 = "Bearing Dataset/1st_test/" except IOError: print( "you have entered either the wrong data directory path for either testset1 or testset2" ) testset1_freq_max1, testset1_freq_max2, testset1_freq_max3, testset1_freq_max4, testset1_freq_max5 = cal_max_freq( all_files_testset1, path_testset1) testset2_freq_max1, testset2_freq_max2, testset2_freq_max3, testset2_freq_max4, testset2_freq_max5 = cal_max_freq( all_files_testset2, path_testset2) # calculating the labels for the bearing which is failed testset1_labelF = cal_Labels(len(all_files_testset1)) testset2_labelF = cal_Labels(len(all_files_testset2)) # creatine a datafRame for which bearing has failed result1 = create_dataframe(testset1_freq_max1, testset1_freq_max2, testset1_freq_max3, testset1_freq_max4, testset1_freq_max5, 1) result1['labels'] = testset1_labelF result2 = create_dataframe(testset2_freq_max1, testset2_freq_max2, testset2_freq_max3, testset2_freq_max4, testset2_freq_max5, 0)
import os def reshapelist(lst): return (list(map(list, zip(*lst)))) try: # user input for the path of the dataset filedir = input("enter the complete directory path to 1st_test/2nd_test ") filepath = input("enter the folder name 1st_test/2nd_test: ") #load the files all_files = os.listdir(filedir) freq_max1, freq_max2, freq_max3, freq_max4, freq_max5 = cal_max_freq( all_files, filepath) except IOError: print("you have entered either the wrong data directory path or filepath") freq = [freq_max1, freq_max2, freq_max3, freq_max4, freq_max5] max_type = input("enter the max type in range 1-5") max_type = int(max_type) if (max_type >= 1 and max_type <= 5): freqmax = reshapelist(freq[max_type - 1]) else: print("you have enter the max type range except 1-5.") # plot the figure fig = plt.figure() plotlabels(freqmax)