0% found this document useful (0 votes)
3 views

Lab4 AI

Artificial Intelligence Lab 4

Uploaded by

21b-039-cs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab4 AI

Artificial Intelligence Lab 4

Uploaded by

21b-039-cs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

6/11/24, 9:48 PM Lab4_AI

In [1]: # Import necessary libraries


from sklearn.datasets import load_breast_cancer
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import warnings
warnings.filterwarnings('ignore')

# Load dataset
data = load_breast_cancer()

# Split dataset into training and testing sets


X = data.data
y = data.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
random_state=42)

# Create a multi-layer perceptron classifier


mlp = MLPClassifier()

# Fit the model on the training data


mlp.fit(X_train, y_train)

# Make predictions on the testing data


predictions = mlp.predict(X_test)

# Calculate the accuracy of the model


accuracy = accuracy_score(y_test, predictions)
print("Accuracy:", accuracy)

Accuracy: 0.9590643274853801

Home Task
In [2]: # Import necessary libraries
from sklearn.datasets import load_breast_cancer
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import warnings
warnings.filterwarnings('ignore')

# Load dataset
data = load_breast_cancer()

# Split dataset into training and testing sets


X = data.data
y = data.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4,
random_state=42)

# Create a multi-layer perceptron classifier


mlp = MLPClassifier()

file:///E:/Downloads/Lab4_AI.html 1/2
6/11/24, 9:48 PM Lab4_AI

# Fit the model on the training data


mlp.fit(X_train, y_train)

# Make predictions on the testing data


predictions = mlp.predict(X_test)

# Calculate the accuracy of the model


accuracy = accuracy_score(y_test, predictions)
print("Accuracy:", accuracy)

Accuracy: 0.9605263157894737

file:///E:/Downloads/Lab4_AI.html 2/2

You might also like