what is regression code example
Example 1: regression model
knn=KNeighborsRegressor()
svr=SVR()
lr=LinearRegression()
dt=DecisionTreeRegressor()
gbm=GradientBoostingRegressor()
ada=AdaBoostRegressor()
rfr=RandomForestRegressor()
xgb=XGBRegressor()
------------------------------------------------------------------------
models=[]
models.append(('KNeighborsRegressor',knn))
models.append(('SVR',svr))
models.append(('LinearRegression',lr))
models.append(('DecisionTreeRegressor',dt))
models.append(('GradientBoostingRegressor',gbm))
models.append(('AdaBoostRegressor',ada))
models.append(('RandomForestRegressor',rfr))
models.append(('XGBRegressor',xgb))
-------------------------------------------------------------------------
from sklearn.metrics import r2_score,mean_squared_error
from sklearn.model_selection import train_test_split,cross_val_score
x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=42)
-------------------------------------------------------------------------
Model=[]
r2score=[]
rmse=[]
cv=[]
for name,model in models:
print('*****************',name,'*******************')
print('\n')
Model.append(name)
model.fit(x_train,y_train)
print(model)
pre=model.predict(x_test)
print('\n')
score=r2_score(y_test,pre)
print('R2score -',score)
r2score.append(score*100)
print('\n')
sc=cross_val_score(model,x,y,cv=5,scoring='r2').mean()
print('cross_val_score -',sc)
cv.append(sc*100)
print('\n')
rmsescore=np.sqrt(mean_squared_error(y_test,pre))
print('rmse_score -',rmsescore)
rmse.append(rmsescore)
print('\n')
------------------------------------------------------------------------
result=pd.DataFrame({'Model':Model,'R2_score':r2score,'RMSEscore':rmse,'Cross_val_score':cv})
result
Example 2: how do you check regression
First, I have to execute my script.
Once the script execution is completed,
I have to analyze the run result to see if there is
any failed test cases. If there is
failed test cases I have to determine
if it is failed due to legitimate
application issue or it is
caused by some script issue.
(the script can be failed due to automation code issue too)
if it is caused by application issue,
I will try to manually reproduce it
and log a defect if I can reproduce.
If it is due to my script, I have to fix it. But this is not
the case most of the time.