示例#1
0
def get_score(data):
    target = 'label'
    feature = [x for x in data.columns if x not in [target, 'id']]
    score_list = []
    for i in range(5):
        x_train, x_test, y_train, y_test = train_test_split(data[feature],
                                                            data[target],
                                                            test_size=0.4,
                                                            random_state=1)
        pred_proba_gdt = 0
        pred_proba_xgb = 0
        pred_proba_rf = 0
        #        ff = []
        for i in range(5):
            pred_proba_gdt += learn(x_train, y_train, x_test, i, 'GDBT')[1]
            pred_proba_xgb += learn(x_train, y_train, x_test, i, 'XGB')[1]
            pred_proba_rf += learn(x_train, y_train, x_test, i, 'RF')

        pred_proba = pred_proba_gdt + pred_proba_rf * 1.5 + pred_proba_xgb * 2.0
        pred_max = np.max(pred_proba, axis=1)
        zipa = zip(*pred_proba)
        zz = pd.DataFrame()
        zz['max'] = pred_max
        zz['p0'] = (zipa[0] / zz['max']).astype('int') * 0
        zz['p1000'] = (zipa[1] / zz['max']).astype('int') * 1000
        zz['p1500'] = (zipa[2] / zz['max']).astype('int') * 1500
        zz['p2000'] = (zipa[3] / zz['max']).astype('int') * 2000
        zz['label'] = zz['p0'] + zz['p1000'] + zz['p1500'] + zz['p2000']
        pred = zz['label'].values
        score = f1(pred, y_test)
        print 'final_score : ' + str(i), score
        score_list.append(score)
    return score_list
示例#2
0
#!/usr/bin/env python

import function

function.f1("F")
示例#3
0
import pygame
from function import f1, f2, f3, f4, display_w, display_h
import numpy as np
import sys

intercept = np.load('stieber_scenario_4.npy')
#intercept = intercept * 2

#intercept = None
img_w = 10
img_h = 10
no_of_crumbs = 50

x = np.linspace(0, display_w - 350, no_of_crumbs)
y_s = [f1(x), f2(x), f3(x), f4(x)]

if len(sys.argv) > 1:
    y = y_s[int(sys.argv[1])]
else:
    y = y_s[0]

black = (0, 0, 0)
white = (255, 255, 255)

gameDisplay = pygame.display.set_mode((display_w, display_h))
pygame.display.set_caption('Interception')
clock = pygame.time.Clock()
gameExit = False
house_img = pygame.image.load('house.jpg')
hansel_gretel_img = pygame.image.load('h_g.jpg')
witch_img = pygame.image.load('game_over.jpg')
from function import extended_rosenbrock_function as f1
from project_messy import extended_rosenbrock_function as f2
from function import extender_powell_singular_function as g1
from project_messy import extender_powell_singular_function as g2
from function import gradient_erf as grad_f1
from function import gradient_epsf as grad_g1
from project_messy import gradient

eps = 1e-6
number = 100
test_points = np.random.normal(scale=1, size=(number, 4))

# test extended_rosenbrock_function
error = 0
for point in test_points:
    if np.linalg.norm(f1(point) - f2(point)) > eps:
        error += 1

if error == 0:
    print "---- function 1 pass test ----"
else:
    print error

# test extender_powell_singular_function
error = 0
for point in test_points:
    if np.linalg.norm(g1(point) - g2(point)) > eps:
        error += 1

if error == 0:
    print "---- function 2 pass test ----"
示例#5
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import function  #导入function模块,也就是以function命名的py文件,里面定义了多种函数 直接function.name(arg0...)引用

print(function.my_abs(2))
p = function.move(2, 3, 4, 2)
print(p[0], p[1])

print(function.quadratic(4, 9, 0))

function.f1(1, 2, 8)

l = [8, 88]
function.f2(*l)
#function.f2(1,2,*l)

d = {'city': 'B', 'gender': 'M', 'address': 'C'}
function.f3(1, 2, **d)  #传入参数时只是对d的一份拷贝,函数中对dict类型修改不影响d
#function.f3(1,2,city='Beijing')
function.f4(1, 2, city='d', gender='M')
function.f5(1, 2, **d)  #当传入**d然后从中取出 city gender对应的值,剩下的在给d
function.f5(*l, **d)  #对于任意函数,都可以通过类似func(*args, **kw)的形式调用它

print(function.product(8))

print(function.fact(100))

print(function.moveH(3, 'A', 'B', 'C'))