'Please input the classweight of the decision tree(** ** ** **):') classweight = [int(item) for item in classweight.split()] wei = [] if classweight[0] == 0: wei.append('balanced') elif classweight[0] == 1028: wei.append(1028) else: wei.append({0: classweight[0], 1: classweight[1]}) if classweight[2] == 0: wei.append('balanced') elif classweight[2] == 1028: wei.append(1028) else: wei.append({0: classweight[2], 1: classweight[3]}) data, label, timeind = function.load_data('f60-23-1119.xlsx', N) data2, label2, timeind2 = function.load_data('f10-23-1119.xlsx', N) N = len(data) # # data, label, timeind = function.createdataset(data, label, timeind, 0.5, N, 5) # # # data2, label2 = function.createdataset(data2, label2, 0.5, N, 2) # indall = [i for i in range(23)] # indall = set(indall) # # indfew = [4,5,6,8,10,12,14,15,16] # indfew = [12] # # indfew = [] # indfew = set(indfew) # indroi = indall - indfew # indroi = list(indroi) # # # indroi = [0,1,2,7,9,11,13,14,21] # ind = np.array(indroi)
import numpy as np from function import load_data from sklearn.linear_model import LogisticRegression from sklearn.preprocessing import MinMaxScaler from sklearn.decomposition import PCA from sklearn.model_selection import KFold from sklearn.metrics import accuracy_score """ ロジスティック回帰を用いて,音声ファイルを2クラスに分類する 10-foldクロスバリデーションより、分類の精度をみる ランダムに2クラス分類を行った場合と比較する """ csv_file_path = r"path/to/data.csv" x_data, y_data = load_data(csv_file_path) x_data = np.array(x_data) y_data = np.array(y_data) # データを10分割する n_fold = 10 k_fold = KFold(n_fold, shuffle=True) accuracy_list = [] train_accuracy_list = [] norm_accuracy_list = [] norm_train_accuracy_list = [] L1_accuracy_list = [] L1_train_accuracy_list = [] PCA_accuracy_list = []
import function as f import time filename = '2017.12.11 Dataset Project 2.csv' C = 6.5 gamma = 0.24 X, Y = f.load_data(filename) Xtr, Xtst, Ytr, Ytst = f.split_data(X, Y) def main(): t = time.time() alpha_star, res = f.find_alpha_star(Xtr, Ytr, C, gamma) totalTime = time.time() - t b_star = f.find_b_star(alpha_star, Xtr, Ytr, C, gamma) #print("b_star: ", b_star) ytstpred = f.predict(alpha_star, b_star, Xtr, Ytr, Xtst, gamma) ytrpred = f.predict(alpha_star, b_star, Xtr, Ytr, Xtr, gamma) test_accuracy = f.acc_score(ytstpred, Ytst) #print("Main train accuracy: ",f.acc_score(ytrpred,Ytr)) output = open("output_homework2_28.txt", "a") # instead of 99, number of the team output.write("Homework 2, question 1") output.write("\nTraining objective function," + "%f" % res.fun)
from spacetime.client.declarations import Producer, GetterSetter, Getter from lxml import html,etree import re, os from time import time from uuid import uuid4 from urlparse import urlparse, parse_qs from uuid import uuid4 # store all the global varaibles from function import save_data, load_data import json # loading global variable file_name = 'data.txt' pages_count, MaxOutputLink, invalid_count, subdomain = load_data(file_name) logger = logging.getLogger(__name__) LOG_HEADER = "[CRAWLER]" @Producer(PaichunwLink) @GetterSetter(OnePaichunwUnProcessedLink) class CrawlerFrame(IApplication): app_id = "Paichunw" def __init__(self, frame): #self.starttime = time() self.app_id = "Paichunw" self.frame = frame
pa = ap.parse_args() where = pa.data_dir path = pa.save_dir lr = pa.learning_rate save_dir = pa.save_dir dropout = pa.dropout power = pa.gpu epochs = pa.epochs architecture = pa.pretrained_model hiddenl = pa.hidden_units trainloader, validloader, testloader, train_data, valid_data, test_data = load_data(where) pretr_model = pa.pretrained_model model = getattr(models, pretr_model)(pretrained = True) build_classifier(model) build_classifier(model) criterion = nn.NLLLoss() optimizer = optim.Adam(model.classifier.parameters(),lr=0.0001) model, optimizer = train_model(model, epochs, trainloader, validloader, criterion, optimizer, power, lr, hiddenl, dropout) test_model(model, testloader) save_model(model, train_data, optimizer, save_dir, epochs, lr, architecture, hiddenl, dropout)
] result_eva.append(tmp) # ******************************1.parameters setting*************************** feature_num = 128 #number of features: ecg+pcg 64 + 64 group_num = 400 #number of feature subset in population best_feature = [] #the optimal subset best_score = 0 #the score of optimal subset times = 0 group = [[random.randint(1, 2) for i in range(feature_num)] for j in range(group_num)] #生成初始种群 for each1 in range(len(group)): for each2 in range(len(group[each1])): if group[each1][each2] > 0: group[each1][each2] = 1 # ****************************** 2.data loading *************************** x_train, y_train, x_test, y_test = function.load_data(params) #scaler.fit_transform(np.vstack([x_train,x_test])) # ****************************** 3.genetic algorithm schedule = range(0, 100, 1) for sch in tqdm.tqdm(schedule): score = [] for i in range(group_num): x_train_tmp = fea_gene_generator(group[i], x_train) x_test_tmp = fea_gene_generator(group[i], x_test) score.append( caculate_fitness(x_train_tmp, y_train, x_test_tmp, y_test)) group_score = [] for index, score in enumerate(score): group_score.append([index, score]) #Sort by the score of each subset group_score = sorted(group_score, key=lambda x: x[1], reverse=True)
""" __title__ = '' __author__ = 'WNI10' __mtime__ = '2018/9/15' """ from sklearn.datasets import load_iris import function # from sklearn import tree if __name__ == '__main__': # iris = load_iris() # clf = tree.DecisionTreeClassifier() # clf = clf.fit(iris.data,iris.target) # # import graphviz # dot_data = tree.export_graphviz(clf,out_file=None) # graph = graphviz.Source(dot_data) # graph.render("iris") # data = load_iris().data # label = load_iris().target # function.OB(data,label) ################################### #画出树形图 ################################### data, label = function.load_data("f60-1-3.xlsx", 1) data, label = function.createdataset(data, label, 0.2, 1, 5) function.OB(data[0], label[0], 'temp', 5, 50, 100)