#importing libraries
import numpy as np
from collections import Counter
import pandas as pd
import lightgbm as lgb
import joblib
from sklearn.datasets import load_breast_cancer,load_boston,load_wine
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.metrics import mean_squared_error,roc_auc_score,precision_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import scale
pd.options.display.max_columns = 999
data = pd.read_csv("iris.csv",skiprows=[0])
X = data.iloc[:,0:-1]
X = scale(X)
Y = data.iloc[:,-1]
#train_test_split
x_train,x_test,y_train,y_test=train_test_split(X,Y,test_size=0.3,random_state=0)
#converting the dataset into proper LGB format
gbr = GradientBoostingClassifier(n_estimators=3000, max_depth=2, min_samples_split=2, learning_rate=0.1)
#gbr = GradientBoostingClassifier(learning_rate=0.1, n_estimators=60,max_depth=7, min_samples_leaf =60,
#min_samples_split =1200, max_features='sqrt', subsample=0.8, random_state=10)
gbr.fit(x_train, y_train.ravel())
joblib.dump(gbr, 'train_model_result4.m') # 保存模型
y_gbr = gbr.predict(x_train)
y_gbr1 = gbr.predict(x_test)
acc_train = gbr.score(x_train, y_train)
acc_test = gbr.score(x_test, y_test)
print(acc_train)
print(acc_test)