本文已参与「新人创作礼」活动,一起开启掘金创作之路
import pdpbox
In [2]:
pdpbox.__version__
Out[2]:
'0.2.1'
In [3]:
import matplotlib
In [4]:
matplotlib.__version__
Out[4]:
'3.1.1'
In [5]:
import numpy as np
import pandas as pd
from sklearn.linear_model import ElasticNetCV, LassoCV, RidgeCV
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.kernel_ridge import KernelRidge
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import RobustScaler
from sklearn.model_selection import KFold, cross_val_score
from sklearn.metrics import mean_squared_error
from mlxtend.regressor import StackingCVRegressor
import xgboost as xgb
import lightgbm as lgb
import warnings
warnings.filterwarnings('ignore')
import pandas as pd
import numpy as np
import zipfile
from sklearn.model_selection import KFold
import lightgbm as lgb
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestRegressor
In [6]:
df=pd.read_excel('训练验证集.xlsx')
In [7]:
y_train=df.iloc[:,-2:-1]
x_train=df.iloc[:,:-2]
In [8]:
# 转换成矩阵
x_train = np.array(x_train)
y_train = np.array(y_train)
In [9]:
rf= RandomForestRegressor(n_estimators=151,
min_samples_split=6,
max_features=0.32757967156069284, # float
max_depth=15,
random_state=2
)
In [10]:
rf.fit(x_train,y_train[:,0])
Out[10]:
RandomForestRegressor(max_depth=15, max_features=0.32757967156069284,
min_samples_split=6, n_estimators=151, random_state=2)
In [11]:
len(rf.estimators_)
Out[11]:
151
In [12]:
estimator=rf.estimators_[7]
estimator
Out[12]:
DecisionTreeRegressor(max_depth=15, max_features=0.32757967156069284,
min_samples_split=6, random_state=2081981515)
In [42]:
from sklearn import tree
tree.plot_tree(estimator)