第四届工业大数据创新代码3(自写)

import datetime
import numpy as np
import pandas as pd
import lightgbm as lgb
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
%matplotlib inline
import tensorflow as tf
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import numpy as np
from lightgbm.sklearn import LGBMRegressor
    df_x_train = pd.read_csv('new/new_my_train.csv')
    df_x_test = pd.read_csv('new/new_my_test.csv')
    df_y_train = pd.read_csv('new/new_label.csv')
    df_y_test = pd.read_csv('new/new_test_label.csv')
    df_x_train.drop('Id', axis=1, inplace=True)
    df_x_test.drop('Id', axis=1, inplace=True)
    df_y_train.drop('Id', axis=1, inplace=True)
    df_y_test.drop('Id', axis=1, inplace=True)
    
    x_train = np.array(df_x_train)
    y_train = np.array(df_y_train)
    x_test = np.array(df_x_test)
    y_test = np.array(df_y_test)
def my_loss(st, sp):
    num_example = sp.shape[0]
    num_size = sp.shape[1]
    w = np.ones(sp.shape)
    b = np.zeros(sp.shape)
    e = np.exp(abs(st - sp)/0.012) - 1
    for j in range(num_size):
        if j == 0:
            LL = 299.85
            UL = 300.15
        else:
            LL = 199.925
            UL = 200.075
        for i in range(num_example):
            if st[i][j] >= LL and st[i][j] <= UL:
                if sp[i][j] < LL or sp[i][j] > UL:
                    w[i][j] = 10
            if st[i][j] <LL:
                b[i][j] = abs(st[i][j] - LL)
                if sp[i][j] >= LL:
                    w[i][j] = 10
            else:
                b[i][j] = abs(st[i][j] - UL)
                if sp[i][j] <= UL:
                    w[i][j] = 10
    a=100*b+1
    score = np.sum(w*e*a) / float(num_example)
    return score
model = LGBMRegressor(boosting_type='gbdt', learning_rate=0.15, 
                 objective='regression', 
               n_jobs=-1)
model.fit(x_train, y_train[:,0])
LGBMRegressor(objective='regression')
y_pred1 = model.predict(x_test)
model.fit(x_train, y_train[:,1])
LGBMRegressor(objective='regression')
y_pred2 = model.predict(x_test)
model.fit(x_train, y_train[:,2])
LGBMRegressor(objective='regression')
y_pred3 = model.predict(x_test)
y_pred=np.zeros((600,3))
y_pred[:,0]=y_pred1
y_pred[:,1]=y_pred2
y_pred[:,2]=y_pred3
accuracy = my_loss(y_test, y_pred)
print('accuracy:'+str(accuracy))
accuracy:12605.78145509091
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值