Spaces:
Sleeping
Sleeping
File size: 1,546 Bytes
8ec5561 f16e14b fafc483 590476a 955e101 8ec5561 f16e14b fafc483 e351186 fafc483 f16e14b 590476a e351186 fafc483 f16e14b e351186 f16e14b 8ec5561 b2b9a26 8ec5561 b2b9a26 8ec5561 b2b9a26 8ec5561 b2b9a26 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import pandas as pd
#import lightgbm as lgb
#from sklearn.preprocessing import LabelEncoder
import subprocess
import sys
import warnings
warnings.filterwarnings('ignore')
try:
import lightgbm as lgb
from sklearn.preprocessing import LabelEncoder
from scipy.stats import boxcox
except:
print("An exception occurred")
subprocess.run([sys.executable, "-m", "pip", "install", "lightgbm"])
subprocess.run([sys.executable, "-m", "pip", "install", "scipy"])
subprocess.run([sys.executable, "-m", "pip", "install", "scikit-learn"])
from sklearn.preprocessing import LabelEncoder
import lightgbm as lgb
from scipy.stats import boxcox
def preprocess_input(input_data):
# Preprocess the input data (assuming a similar preprocessing as in the training script)
input_data['rain'] = boxcox(input_data['rain'] + 1)[0]
return input_data
def load_model(model_path='inference/lgbm_model.txt'):
# Load the trained LightGBM model
model = lgb.Booster(model_file=model_path)
return model
def predict(input_data, model):
# Preprocess the input data
preprocessed_data = preprocess_input(pd.DataFrame([input_data]))
# Make predictions using the loaded model
prediction = model.predict(preprocessed_data, num_iteration=model.best_iteration)
predicted_class = prediction.argmax(axis=1)
# Decode the predicted class (inverse transform)
label_encoder = LabelEncoder()
predicted_label = label_encoder.inverse_transform(predicted_class)[0]
return predicted_label
|