Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 56
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
22_23-J 56
22_23-J 56
Commits
475624cd
Commit
475624cd
authored
Feb 17, 2023
by
IT19954806 Devindi L.A.P.S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file of Random forest model
parent
a6f93cf1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
Random Forest Model
Random Forest Model
+34
-0
No files found.
Random Forest Model
0 → 100644
View file @
475624cd
# Feeding the data into the algorithm
rf_model = RandomForestRegressor(n_estimators=100, max_depth=20)
rf_model.fit(x_train, y_train)
rf_pred = rf_model.predict(x_test)
# Transform the prediction back to it's original state
rf_pred = rf_pred.reshape(-1,1)
rf_pred_test_set = np.concatenate([rf_pred, x_test], axis=1)
rf_pred_test_set = scaler.inverse_transform(rf_pred_test_set)
# calculating the predicted exports values from the difference values and append that to the predicted data frame
result_list = []
for index in range(0, len(rf_pred_test_set)):
result_list.append(rf_pred_test_set[index][0] + act_exports[index])
rf_pred_series = pd.Series(result_list, name='rf_pred')
predict_df = predict_df.merge(rf_pred_series, left_index=True, right_index=True)
# Now that we have calculated the predicted data and now we can evaluate it with varius matrix to test it's accuracy
rf_rmse = np.sqrt(mean_squared_error(predict_df['rf_pred'], monthly_exports['Quantity'][-12:]))
rf_mae = mean_absolute_error(predict_df['rf_pred'], monthly_exports['Quantity'][-12:])
rf_r2 = r2_score(predict_df['rf_pred'], monthly_exports['Quantity'][-12:])
print('Random Forest RMSE: ', rf_rmse)
print('Random Forest MAE: ', rf_mae)
print('Random Forest R2 Score: ', rf_r2)
# Visualising the data with the original values
plt.figure(figsize=(15,7))
plt.plot(monthly_exports['Date'], monthly_exports['Quantity'])
plt.plot(predict_df['Date'], predict_df['rf_pred'])
plt.title("Export Forecast using Random Forest")
plt.xlabel("Date")
plt.ylabel("Exports")
plt.legend(["Original exports", "Predicted exports"])
plt.show()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment