Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COMP3217
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sps2n22
COMP3217
Commits
793ae458
Commit
793ae458
authored
2 years ago
by
sps2n22
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
9b4ee4d9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
task2.py
+40
-0
40 additions, 0 deletions
task2.py
with
40 additions
and
0 deletions
task2.py
0 → 100644
+
40
−
0
View file @
793ae458
# Importing libraries
import
pandas
as
pd
import
seaborn
as
sns
from
sklearn.linear_model
import
LogisticRegression
from
sklearn
import
datasets
import
matplotlib.pyplot
as
plt
from
sklearn.metrics
import
accuracy_score
,
f1_score
from
sklearn.inspection
import
DecisionBoundaryDisplay
import
matplotlib.pyplot
as
plt
from
sklearn.ensemble
import
RandomForestClassifier
from
sklearn.model_selection
import
train_test_split
# Importing the csv files
testDF
=
pd
.
read_csv
(
'
TestingDataMulti.csv
'
,
header
=
None
)
trainDF
=
pd
.
read_csv
(
'
TrainingDataMulti.csv
'
,
header
=
None
)
# Use of Random forest model function
randomfunc
=
RandomForestClassifier
()
# Getting the data reading for fitting
X
=
trainDF
.
iloc
[:,:
-
1
]
y
=
trainDF
.
iloc
[:,
-
1
]
#Creating the variables for both testing and training by splitting the data into 80% for training and 20% for testing.
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
.
2
,
random_state
=
21
)
randomfunc
.
fit
(
X_train
,
y_train
)
y_predictDF
=
randomfunc
.
predict
(
X_test
)
# Computing the prediction error
prediction_error
=
1
-
accuracy_score
(
y_test
,
y_predictDF
)
print
(
"
Prediction Error:
"
,
prediction_error
)
# Predicting using the X_test variable
accuracy
=
accuracy_score
(
y_test
,
y_predictDF
)
print
(
"
Accuracy:
"
,
accuracy
)
# Evaluating and Displaying the accuracy of our predictions
label
=
randomfunc
.
predict
(
testDF
)
# By utilizing the testing data, we determine the anticipated values/predictions.
Output
=
pd
.
DataFrame
(
label
,
columns
=
[
'
Prediction
'
])
# Saving the predictions to a CSV file
testDF
[
'
Prediction
'
]
=
Output
[
"
Prediction
"
].
tolist
()
testDF
.
to_csv
(
"
TestingResultsMulti.csv
"
,
index
=
False
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment