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