<jupyter_start><jupyter_text>IntroducitionIn this project we predict the price group (e.g. low, high, very high) from set of features including ['battery_power', 'dual_sim', 'n_cores',...]. The dataset is avilable from Kaggle website [here](https://www.kaggle.com/iabhishekofficial/mobile-price-classification). Libraries<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from sklearn.preprocessing import OneHotEncoder,StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix<jupyter_output><empty_output><jupyter_text>Mobile Dataset<jupyter_code>df_train = pd.read_csv('datasets_11167_15520_train.csv')
df_test = pd.read_csv('datasets_11167_15520_test.csv')
df_train.head(2)
# df_test.head(2)
# Columns data type
df_train.dtypes
# the target value analysis
df_train['price_range'].value_counts()
df_train['price_range'].hist()
plt.show()
#  convert the target column to one-hot encode
y = df_train['price_range'].values.reshape(-1,1)
y = OneHotEncoder().fit_transform(y).toarray()
# or we can use 'get_dummies'
# y_train = pd.get_dummies(df_train['price_range']).values.shape
# drop the target column so we get all the features we use in the training
x = np.asarray(df_train.drop('price_range', axis=1))
# normlise the features
x = StandardScaler().fit(x).fit_transform(x)
# splite the train set into training 70% and valdation 30%
x_train, x_test , y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=7)
x_test.shape
# define the model
model = Sequential()
model.add(Dense(16, input_dim = x_train.shape[1], activation='relu'))
model.add(Dense(16, activation='relu'))
model.add(Dense(4, activation='softmax'))
# compile the model
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics='acc')
history = model.fit(x_train, y_train, batch_size=64, epochs=100,verbose=1, validation_data=(x_test, y_test))
# predict on the test set
y_hat = model.predict(x_test)
# extract the accuracy score on the testset
accuracy_score(y_test.argmax(axis=1), y_hat.argmax(axis=1))
# extract the evalution metrices on the test set
print(classification_report(y_test.argmax(axis=1), y_hat.argmax(axis=1)))
# extract the confusion matrix
cm = confusion_matrix(y_test.argmax(axis=1), y_hat.argmax(axis=1))
# plot the confusion matrix
plt.imshow(cm, alpha=0.7,cmap=plt.cm.Blues)
plt.xlabel('ff')
plt.colorbar()

# plot the training&valdation accuracy and loss
accuray = history.history['acc']
val_accuray = history.history['val_acc']
error  = history.history['loss']
val_error  = history.history['val_loss']
plt.figure()
plt.plot( range(len(accuray)), accuray, label='train' )
plt.plot(val_accuray, label='val')
plt.xlabel('epoch')
plt.ylabel('accurcy')
plt.legend()
plt.figure()
plt.plot( range(len(accuray)), error, label='train')
plt.plot( range(len(accuray)), val_error, label='train')
plt.xlabel('epoch')
plt.ylabel('loss')
plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1325105553751218, 'fraction_numerical': 0.016888600194868465, 'mean_word_length': 7.461538461538462, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '314998', 'license': 'MIT', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1069, 'n_words': 243, 'path': 'KaggleCompititon_Mobile_Price_Classification_Using_NN.ipynb', 'repo_name': 'MohamadALissa/KaggleCompititon_Mobile_Price_Classification_Using_NN', 'size': '3079'}