text_plain_output_1.png
from sklearn.linear_model import LogisticRegression

from sklearn.model_selection import KFold, train_test_split, cross_val_score

from sklearn.preprocessing import StandardScaler

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

train = pd.read_csv('/kaggle/input/mobile-price-classification/train.csv')

train.isna().any()

g = sns.catplot(x="blue",y="price_range",data=train, kind = 'bar', height = 6, 
palette = "muted")
g.despine(left=True)
g = g.set_ylabels("price_range")

g = sns.catplot(x="wifi",y="price_range",data=train, kind = 'bar', height = 6, 
palette = "muted")
g.despine(left=True)
g = g.set_ylabels("price_range")

g = sns.catplot(x="n_cores",y="price_range",data=train, kind = 'bar', height = 6, 
palette = "muted")
g.despine(left=True)
g = g.set_ylabels("price_range")

plt.figure(figsize=(15, 12))
g = sns.heatmap(train.corr(),cmap="BrBG",annot=True, linewidths = 2.0)

scaler = StandardScaler()
X = scaler.fit_transform(train.drop(['price_range'], axis=1))
y = np.ravel(train[['price_range']])

kf = KFold(n_splits=5)

kf.get_n_splits(X)

training_scores_log = []
testing_scores_log = []
for fold, (train_index, test_index) in enumerate(kf.split(X)):
    X_train = X[train_index]
    y_train = y[train_index]
    X_test = X[test_index]
    y_test = y[test_index]
    clf_log = LogisticRegression(random_state=0).fit(X_train, y_train)
    print(f'Fold {fold + 1} -> The score of the training data set is: ', clf_log.score(X_train, y_train))
    print(f'Fold {fold + 1} -> The score of the testing (out of fold) data set is: ', clf_log.score(X_test, y_test))
    training_scores_log.append(clf_log.score(X_train, y_train))
    testing_scores_log.append(clf_log.score(X_test, y_test))
    print('\n')
print(f'The average training set accuracy is: {sum(training_scores_log) / len(training_scores_log)}')
print(f'The average testing set accuracy is: {sum(testing_scores_log) / len(testing_scores_log)}')