from pylab import rcParams
class Fitted_DataPoints_vs_ActualPoints(Data_Modelling):
def __init__(self,n_estimators,
max_depth,
min_samples_split,
min_samples_leaf,
max_leaf_nodes,
min_impurity_split,
min_impurity_decrease,
bootstrap,
min_child_weight,
learning_rate,
Subsample,
Alpha,
Lamda,
random_state,
criterion):
Data_Modelling.__init__(self,n_estimators,
max_depth,
min_samples_split,
min_samples_leaf,
max_leaf_nodes,
min_impurity_split,
min_impurity_decrease,
bootstrap,
min_child_weight,
learning_rate,
Subsample,
Alpha,
Lamda,
random_state,
criterion)
print("Data Points object created")
def Random_Forest_Model(self,df):
RF_Regressor = RandomForestRegressor(n_estimators = self.n_estimators,
max_depth = self.max_depth,
min_samples_split = self.min_samples_split,
min_samples_leaf = self.min_samples_leaf,
max_leaf_nodes = self.max_leaf_nodes,
bootstrap = self.bootstrap,
criterion = self.criterion)
RF_Regressor.fit(x_train,y_train)
RF_pred=RF_Regressor.predict(x_test)
np.sqrt(metrics.mean_squared_error(y_test,RF_pred))
r2_score(y_test,RF_pred)
rcParams['figure.figsize'] = 10, 10
fig, ax = plt.subplots()
ax.scatter(y_test, RF_pred)
ax.plot([y.min(), y.max()], [y.min(), y.max()], 'k--', lw=4)
print('Customer LifeTime Value Prediction :: Data Points vs Fitted Lines')
ax.set_xlabel('Actual')
ax.set_ylabel('Predicted')
plt.show()
DP = Fitted_DataPoints_vs_ActualPoints(500,5,3,3,None,1,0.1,True,3,0.07,0.7,0,1.5,29,'mse')
DP.Random_Forest_Model(df)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter