refer to code:
.
from sklearn.metrics import r2_score,mean_squared_error
from sklearn.ensemble import RandomForestRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import seaborn as sns
from math import sqrt
import numpy as np
import pandas as pd
import warnings
warnings.filterwarnings('ignore')
features = pd.read_csv('./features.csv')
label = pd.read_csv('./label.csv')
features.head()
label.head()
#------------------------------------ data split ---------------------------------------------
X_train,X_test,y_train,y_test = train_test_split(features,label,test_size=0.20,random_state=33)
#------------------------------------ RandomForestRegressor ---------------------------------------------
RFRmodel = RandomForestRegressor(max_depth=3, random_state=0)
RFRmodel.fit(X_train,y_train)
y_pred = RFRmodel.predict(X_test)
print('RandomForestRegressor')
print("R2 score :",r2_score(y_test, y_pred))
print("MSE score :",mean_squared_error(y_test, y_pred))
print("RMSE: ",sqrt(mean_squared_error(y_test, y_pred)))
print('')
#------------------------------------ DecisionTreeRegressor---------------------------------------------
DTRmodel = DecisionTreeRegressor(max_depth=3,random_state=0)
DTRmodel.fit(X_train,y_train)
y_pred = DTRmodel.predict(X_test)
print('DecisionTreeRegressor')
print("R2 score :",r2_score(y_test, y_pred))
print("MSE score :",mean_squared_error(y_test, y_pred))
print("RMSE: ",sqrt(mean_squared_error(y_test, y_pred)))
print('')
#------------------------------------ LinearRegression ---------------------------------------------
model = LinearRegression()
model.fit(X_train,y_train)
y_pred = model.predict(X_test)
print('LinearRegression')
print("R2 score :",r2_score(y_test, y_pred))
print("MSE score :",mean_squared_error(y_test, y_pred))
print("RMSE: ",sqrt(mean_squared_error(y_test, y_pred)))
print('')
..
You can download dataset from here:
Thank you.
www.marearts.com
ππ»♂️
No comments:
Post a Comment