def update_files(): input_data = [] for i in range(1, 6): with open(f'in\\{str(i)}.csv', encoding='utf-8', newline='') as f_in: for row in csv_read(f_in): row.insert(0, companies[i]) input_data.append(row) # generating output data output_data = {1: [], 2: [], 3: []} for line in input_data: if 'производитель 1' in line: output_data[1].append(line[:3] + line[4:]) elif 'производитель 3' in line: output_data[2].append(line[:3] + line[4:]) if 'яблоки' in line: output_data[3].append(line[:1] + line[2:]) for i in range(1, 4): with open(f'out\\{str(i)}.csv', 'w', encoding='utf-8', newline='') as f_out: csv_write(f_out).writerows(output_data[i]) return None
# from sklearn.linear_model import LogisticRegression # from sklearn.neural_network import MLPClassifier from sklearn import svm from sklearn.tree import DecisionTreeClassifier from sklearn.preprocessing import StandardScaler, PolynomialFeatures print("Import finished") parameter_num = 15 # the number of mfcc's parameters train_pos_num = 100 train_neg_num = 100 test_num = 100 dataset_root = 'D:/dataset' train_label = np.array([1] * train_pos_num + [0] * train_neg_num) test_label = [0] * test_num csv_list_test = csv_read( open('D:/dataset/test_result.csv', 'r', encoding='utf-8')) csv_list_test = list(csv_list_test)[0] csv_list_test[0] = csv_list_test[0].strip('\ufeff') for i in range(test_num): test_label[i] = int(csv_list_test[i]) test_label = np.array(test_label) # 1.图像特征向量读取 image_read_flag = 0 image_train_pos_root = './image_feat/train_pos.npy' image_train_neg_root = './image_feat/train_neg.npy' image_test_root = './image_feat/test.npy' if not os_path_exists('./image_feat/'): makedirs('./image_feat/') image_read_flag = 1
# import matplotlib.pyplot as plt # from sklearn.model_selection import train_test_split, learning_curve, validation_curve from sklearn.preprocessing import StandardScaler, PolynomialFeatures # , Normalizer from sklearn.neural_network import MLPClassifier print("Import finished") parameter_num = 15 # the number of mfcc's parameters train_pos_num = 100 train_neg_num = 100 test_num = 100 dataset_root = 'D:/Temp/Matlab/Machine_Learning/dataset' train_label = np.array([1] * train_pos_num + [0] * train_neg_num) test_label = [0] * test_num csv_list_test = csv_read( open('D:/Temp/Matlab/Machine_Learning/dataset/test_result.csv', 'r', encoding='utf-8')) csv_list_test = list(csv_list_test)[0] csv_list_test[0] = csv_list_test[0].strip('\ufeff') for i in range(test_num): test_label[i] = int(csv_list_test[i]) test_label = np.array(test_label) # 1.图像特征向量读取 image_read_flag = 0 image_train_pos_root = './image_feat/train_pos.npy' image_train_neg_root = './image_feat/train_neg.npy' image_test_root = './image_feat/test.npy' if not os_path_exists('./image_feat/'): makedirs('./image_feat/') image_read_flag = 1
def csv_write(self, pfadname, delimiter): """ Eine Methode zum Schreiben von CSV-Dateien """ ifile = open(self.filename) #Oeffnen des vorhandenen Files sn = csv.Sniffer() dialect = sn.sniff(ifile.read(1024)) reader = csv.reader(ifile, dialect) ofile = open(pfadname, "w") #Oeffnen des Files, in welches hineingeschrieben werden soll writer = csv.writer(ofile, delimiter=delimiter, quotechar='"', quoting=csv.QUOTE_ALL) #Setzen des Writers for row in reader: writer.writerow(row) #Schreiben in das File #Schliessen der beiden Dateien ifile.close() ofile.close() if __name__ == "__main__": """ Definition der Main, Aufrufen der Read und Write Methoden """ csv = CSVreader("WahlKopie.csv") #Angeben der Datei read = csv.csv_read() #Lesen der Datei csv.csv_write("WahlNeu.csv", '\t') #Schreiben in ein neues File #print (read) #Ausgeben des Eingelesenen
from csv import reader as csv_read import numpy as np from utils.general_plotting import smooth_histogram from matplotlib import pyplot as plt from scipy.stats import ks_2samp from utils.linalg import moving_average master_table = [] with open(my_file, 'r') as source: reader = csv_read(source) header = reader.next() for line in reader: line = [float(elt) if elt else np.nan for elt in line[1:-3]] master_table.append(line) master_table = np.array(master_table) D_r = master_table[master_table[:, -1] > 0., 1] D_nr = master_table[master_table[:, -1] == 0., 1] GM_r = master_table[master_table[:, -1] > 0., 0] GM_nr = master_table[master_table[:, -1] == 0., 0] S_r = master_table[master_table[:, -1] > 0., 2] S_nr = master_table[master_table[:, -1] == 0., 2] s_r = master_table[master_table[:, -1] > 0., -2] s_nr = master_table[master_table[:, -1] == 0., -2] s_3d_av = moving_average( master_table[np.logical_not(np.isnan(master_table[:, -1])), -2], 3)