使用lightgbm进行故障诊断

import pandas as pd
from sklearn.model_selection import GridSearchCV
import lightgbm as lgb
from sklearn.metrics import f1_score
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.datasets import make_classification
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split,cross_val_score
from bayes_opt import BayesianOptimization
import warnings
warnings.filterwarnings("ignore")


df = pd.read_csv('C:\\Users\\asus\\Desktop\\数据\\zhiyintu.csv') 
X2=df.iloc[:,4:6]   #比值系数
y1=df['guzhang']

XD1=[]
yD1=[]


#增多第5、10 、11、12个故障

for i in range(len(y1)):
    XX=X2[i:i+1]
    yy=y1[i:i+1]
    XXX = np.tile(np.array(XX),(100,1)) + abs(np.tile(np.array(XX),(100,1)))*0.1*np.random.randn(1*100,2)
    yyy = np.tile(np.array(yy),(100)) 
    XD1.append(XXX)
    yD1.append(yyy)
    
nqf = [5,10,11,12]    
for i  in nqf:
    XX=X2[i:i+1]
    yy=y1[i:i+1]

    

XXXX1=np.r_[XD1[0],XD1[1],XD1[2],XD1[3],XD1[4],XD1[5],XD1[6],XD1[7],XD1[8],XD1[9],XD1[10],XD1[11],XD1[12]]
yyyy1=np.r_[yD1[0],yD1[1],yD1[2],yD1[3],yD1[4],yD1[5],yD1[6],yD1[7],yD1[8],yD1[9],yD1[10],yD1[11],yD1[12]]

x_train, x_test, y_train, y_test = train_test_split(XXXX1, yyyy1, test_size=0.25, random_state=33)

lightgbm  = lgb.sklearn.LGBMClassifier()
param_grid = {
    'learning_rate': [0.01, 0.1, 0.5],
    'n_estimators': [30, 40]
}
lightgbm = GridSearchCV(lightgbm, param_grid)
lightgbm.fit(x_train, y_train)
y_lgb = lightgbm.predict(x_test)
print(f1_score(y_test, y_lgb , average='weighted'))  


展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读