OER·harvester

← Back to the library
Zenodo PDF resource

Artificial intelligence (AI) with It's Applications

The book "Artificial Intelligence (AI) with It's Applications" provides a comprehensive insight into the field of AI, exploring its fundamental principles, modern applications, and future potential. It serves as a valuable resource for students, researchers, and professionals looking to understand AI’s role in shaping industries and everyday life. The book begins with an introduction to Artificial Intelligence , cov…

Licence
OPEN CC-BY-4.0
Authors
Dr. Dipikaben Umakant Thakar, Mrs. PL. Natchiammai, Dr. R. J. Kavitha…
Published
2025-03-18 · Zenodo
Language
eng
Length
66700 words
Type
narrative text
Open ↗ Download Open original ↗

Impute missing values after splitting

from sklearn.impute import SimpleImputer

imputer = SimpleImputer(strategy='mean') # Or another strategy like 'median'

xtrain = imputer.fit_transform(xtrain)

xtest = imputer.transform(xtest)

xtrain.shape, xtest.shape

Output

((5197, 10), (1300, 10))

Normalising the data before training help us to achieve stable and fast training of the model.

norm = MinMaxScaler()

xtrain = norm.fit_transform(xtrain)

xtest = norm.transform(xtest)

As the data has been prepared completely let’s train some state of the art machine learning model on it.

models = [LogisticRegression(), XGBClassifier(), SVC(kernel='rbf')]

for i in range(3):

models[i].fit(xtrain, ytrain)

print(f'{models[i]} : ')

print('Training Accuracy : ', metrics.roc_auc_score(ytrain, models[i].predict(xtrain)))

print('Validation Accuracy : ', metrics.roc_auc_score(

ytest, models[i].predict(xtest)))

print()

Output

LogisticRegression() :

Training Accuracy : 0.6975101024661644

Validation Accuracy : 0.6855058693719925

XGBClassifier() :

Training Accuracy : 0.9762240429934201

Validation Accuracy : 0.8045662590288206

SVC() :

Training Accuracy : 0.7203202525576721

Validation Accuracy : 0.7073819229472522

Model Evaluation

From the above accuracies we can say that Logistic Regression and SVC() classifier performing better on the validation data with less difference between the validation and training data. Let’s plot the confusion matrix as well for the validation data using the Logistic Regression model.

from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay

import matplotlib.pyplot as plt