0% found this document useful (0 votes)
7 views3 pages

Project - CSF344 and CSN344-Machine Learning

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Project - CSF344 and CSN344-Machine Learning

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Project – CSF344, Machine Learning, ODDSem, III Year

StudentName: Krishna Kant Singh ID: 1000021294 Major: MCA

Instructions
 There are two questionsin this assignment.
 Email/paper/other modes of submissions will not be accepted.
 Upload a word version of this document.
 Assignment submitted after due date will not be evaluated and a score of zero will
be awarded.
 Plagiarism may lead to award of zero marks.

Due Date:6:00 pm, 15th Nov, 2024.

Submitting this Assignment

You will submit (upload) this assignment in MS Teams. Name this document as
GLA1_AJPODD2024_John_Doe.doc in case your name is John Doe, and this graded lab
assignment is 1 of course whose acronym is AJP, and offered in ODD 2024. Paste your
codeafter each question, paste the screenshot of output, save and upload the document.

Grading Scheme: This assignment has 5 marks.

Question 1:
Create an ML model using any one of the algorithms given below.
i. Decision Tree
ii. Random Forest
iii. Support Vector Machine

And calculate the following using a dataset of your choice


a. Confusion Matrix
b. Accuracy
c. F1-Score
d. Precision
Source Code
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix, accuracy_score, f1_score,
precision_score
from sklearn.preprocessing import LabelEncoder, StandardScaler

file_path = "Iris.csv"
data = pd.read_csv(file_path)

le = LabelEncoder()
data['Species'] = le.fit_transform(data['Species'])

X = data.drop(columns=["Species"])
y = data["Species"]

scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.3,


random_state=42)

model = LogisticRegression(max_iter=500)
model.fit(X_train, y_train)

y_pred = model.predict(X_test)

conf_matrix = confusion_matrix(y_test, y_pred)


accuracy = accuracy_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred, average="weighted")
precision = precision_score(y_test, y_pred, average="weighted")

print("Confusion Matrix:")
print(conf_matrix)
print("\nAccuracy:", accuracy)
print("F1-Score:", f1)
print("Precision:", precision)
Project – CSF344, Machine Learning, ODDSem, III Year

StudentName: Krishna Kant Singh ID: 1000021294 Major: MCA

Output:

You might also like