bases += [LinearClassify, LogisticClassify] def test(trd, trc, ted, tec): print('bc', '\n') bc = BaggedClassify(bases[np.random.randint(len(bases))], 20, trd, trc) print(bc, '\n') # print(bc.predict(ted), '\n') # print(bc.predict_soft(ted), '\n') # print(bc.confusion(ted, tec), '\n') print(bc.auc(ted, tec), '\n') print(bc.roc(ted, tec), '\n') err = bc.err(ted, tec) print(err, '\n') return err avg_err = test_randomly(bd1, bc1, 0.8, test) print('avg_err') print(avg_err) ## DETERMINISTIC TESTING ####################################################### # np.set_printoptions(linewidth=200) # # data = [[float(val) for val in row[:-1]] for row in csv.reader(open('../data/classifier-data.csv'))] # trd = np.asarray(data[0:40] + data[50:90] + data[100:140]) # ted = np.asarray(data[40:50] + data[90:100] + data[140:150]) # classes = [float(row[-1].lower()) for row in csv.reader(open('../data/classifier-data.csv'))] # trc = np.asarray(classes[0:40] + classes[50:90] + classes[100:140]) # tec = np.asarray(classes[40:50] + classes[90:100] + classes[140:150]) #
bd1, bc1 = np.array(bd1), np.array(bc1) def test(trd, trc, ted, tec): print('tc', '\n') tc = TreeClassify(trd, trc) print(tc, '\n') # print(tc.predict(ted), '\n') # print(tc.predict_soft(ted), '\n') # print(tc.confusion(ted, tec), '\n') # print(tc.auc(ted, tec), '\n') # print(tc.roc(ted, tec), '\n') err = tc.err(ted, tec) print(err, '\n') return err avg_err = test_randomly(data, classes, 0.8, test) print('avg_err') print(avg_err) ## DETERMINISTIC TESTING ####################################################### # data = [[float(val) for val in row[:-1]] for row in csv.reader(open('../data/classifier-data.csv'))] # trd = np.asarray(data[0:40] + data[50:90] + data[100:140]) # ted = np.asarray(data[40:50] + data[90:100] + data[140:150]) # classes = [float(row[-1].lower()) for row in csv.reader(open('../data/classifier-data.csv'))] # trc = np.asarray(classes[0:40] + classes[50:90] + classes[100:140]) # tec = np.asarray(classes[40:50] + classes[90:100] + classes[140:150]) # # btrd = trd[0:80,:] # bted = ted[0:20,:]
err = gd.mse(ted, tec) print('gd.mse =', err, '\n') print('gd.predict(ted)') print(gd.predict(ted)) print('gd.get_n()') print(gd.get_n()) gd.train(base, 6, X2, Y2) print('gd.get_n()') print(gd.get_n()) err = gd.mse(ted, tec) print('gd.mse =', err, '\n') print('gd.predict(ted)') print(gd.predict(ted)) return err avg_err = test_randomly(data, predictions, 0.8, test=test, end=1) print('avg_err') print(avg_err) ################################################################################ ################################################################################ ###############################################################################
bd1,bc1 = np.array(bd1), np.array(bc1) def test(trd, trc, ted, tec): print('gbc', '\n') gbc = GaussBayesClassify(trd, trc) print(gbc, '\n') # print(gbc.predict(ted), '\n') # print(gbc.predict_soft(ted), '\n') # print(gbc.confusion(ted, tec), '\n') # print(gbc.auc(ted, tec), '\n') # print(gbc.roc(ted, tec), '\n') err = gbc.err(ted, tec) print(err, '\n') return err avg_err = test_randomly(data, classes, 0.8, test) print('avg_err') print(avg_err) ## DETERMINISTIC TESTING ####################################################### # # data = [[float(val) for val in row[:-1]] for row in csv.reader(open('../data/classifier-data.csv'))] # trd = np.asarray(data[0:40] + data[50:90] + data[100:140]) # ted = np.asarray(data[40:50] + data[90:100] + data[140:150]) # classes = [float(row[-1].lower()) for row in csv.reader(open('../data/classifier-data.csv'))] # trc = np.asarray(classes[0:40] + classes[50:90] + classes[100:140]) # tec = np.asarray(classes[40:50] + classes[90:100] + classes[140:150]) # # btrd = trd[0:80,:] # bted = ted[0:20,:]
if __name__ == "__main__": ## RANDOM TESTING ############################################################## data, predictions = load_data_from_csv("../data/regressor-data.csv", -1, float) data, predictions = arr(data), arr(predictions) def test(trd, trc, ted, tec): print("knnr", "\n") knnr = KNNRegress(trd, trc) print(knnr, "\n") err = knnr.mae(ted, tec) print(err, "\n") return err avg_err = test_randomly(data, predictions, 0.8, test) print("avg_err") print(avg_err) ## DETERMINISTIC TESTING ####################################################### # data = [[float(val) for val in row[:-1]] for row in csv.reader(open('../data/regressor-data.csv'))] # trd = np.asarray(data[0:40] + data[50:90] + data[100:140]) # ted = np.asarray(data[40:50] + data[90:100] + data[140:150]) # trd2 = np.asarray(data[150:180] + data[200:230] + data[250:280]) # ted2 = np.asarray(data[180:200] + data[230:250] + data[280:300]) # trd3 = np.asarray(data[300:320] + data[350:370] + data[400:420]) # ted3 = np.asarray(data[320:350] + data[370:400] + data[420:450]) # predictions = [float(row[-1].lower()) for row in csv.reader(open('../data/regressor-data.csv'))] # trp = np.asarray(predictions[0:40] + predictions[50:90] + predictions[100:140])
print('lr.predict(ted)') print(lr.predict(ted)) err = lr.mse(ted, tec) print('lr.mse(ted, tec) =', err) err = lr.mae(ted, tec) print('lr.mae(ted, tec) =', err) err = lr.rmse(ted, tec) print('lr.rmse(ted, tec) =', err) return err avg_err = test_randomly(X, Y, 0.8, test=test, end=100) print('avg_err') print(avg_err) ## DETERMINISTIC TESTING ####################################################### # data = [[float(val) for val in row[:-1]] for row in csv.reader(open('../data/regressor-data.csv'))] # trd = np.asarray(data[0:40] + data[50:90] + data[100:140]) # ted = np.asarray(data[40:50] + data[90:100] + data[140:150]) # trd2 = np.asarray(data[150:180] + data[200:230] + data[250:280]) # ted2 = np.asarray(data[180:200] + data[230:250] + data[280:300]) # trd3 = np.asarray(data[300:320] + data[350:370] + data[400:420]) # ted3 = np.asarray(data[320:350] + data[370:400] + data[420:450]) # # predictions = [float(row[-1].lower()) for row in csv.reader(open('../data/regressor-data.csv'))]