<jupyter_start><jupyter_text>** checking for missing values****<jupyter_code>df.isnull().sum()<jupyter_output><empty_output><jupyter_text>Handling Missing ValuesMEAN -> AVERAGEMODE -> MORE REPEATED VALUE<jupyter_code>df['Item_Weight'].mean()<jupyter_output><empty_output><jupyter_text>filling missing values in "Item-Weight" with MEAN VALUE<jupyter_code>df['Item_Weight'].fillna(df['Item_Weight'].mean(), inplace=True)
# Mode of "Outlet_Size" column
df['Outlet_Size'].mode()
# filling the missing values in "Outlet_Size" column with Mode
mode_of_Outlet_size = df.pivot_table(values='Outlet_Size', columns='Outlet_Type', aggfunc=(lambda x: x.mode()[0]))
print(mode_of_Outlet_size)
miss_values = df['Outlet_Size'].isnull()
print(miss_values)
df.loc[miss_values, 'Outlet_Size'] = df.loc[miss_values, 'Outlet_Type'].apply(lambda x:mode_of_Outlet_size[x])
#checking for missing values
df.isnull().sum()<jupyter_output><empty_output><jupyter_text>**Data Analysis**<jupyter_code>df.describe()<jupyter_output><empty_output><jupyter_text>** Item_Weight distribution**<jupyter_code>plt.figure(figsize=(6,6))
sns.distplot(df['Item_Weight'])
plt.show()<jupyter_output><empty_output><jupyter_text>** Item Visibility distribution**<jupyter_code>plt.figure(figsize=(6,6))
sns.distplot(df['Item_Visibility'])
plt.show()<jupyter_output><empty_output><jupyter_text>** Item MRP distribution**<jupyter_code>plt.figure(figsize=(6,6))
sns.distplot(df['Item_MRP'])
plt.show()<jupyter_output><empty_output><jupyter_text>Item_Outlet_Sales distribution<jupyter_code>plt.figure(figsize=(6,6))
sns.distplot(df['Item_Outlet_Sales'])
plt.show()<jupyter_output><empty_output><jupyter_text>** Outlet_Establishment_Year column**<jupyter_code>plt.figure(figsize=(6,6))
sns.countplot(x='Outlet_Establishment_Year', data=df)
plt.show()<jupyter_output><empty_output><jupyter_text>** Item_Fat_Content column**<jupyter_code>plt.figure(figsize=(6,6))
sns.countplot(x='Item_Fat_Content', data=df)
plt.show()<jupyter_output><empty_output><jupyter_text>** Item_Type column**<jupyter_code>plt.figure(figsize=(30,6))
sns.countplot(x='Item_Type', data=df)
plt.show()<jupyter_output><empty_output><jupyter_text>** Outlet_Size column**<jupyter_code>plt.figure(figsize=(6,6))
sns.countplot(x='Outlet_Size', data=df)
plt.show()<jupyter_output><empty_output><jupyter_text>**Data Pre=Processing**<jupyter_code>df.head()
df['Item_Fat_Content'].value_counts()
df.replace({'Item_Fat_Content':{'low fat':'Low Fat', 'LF':'Low Fat', 'reg':'Regular'}},inplace=True)
df['Item_Fat_Content'].value_counts()<jupyter_output><empty_output><jupyter_text>**Label Encoding**<jupyter_code>from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()
df['Item_Identifier'] = encoder.fit_transform(df['Item_Identifier'])

df['Item_Fat_Content'] = encoder.fit_transform(df['Item_Fat_Content'])

df['Item_Type'] = encoder.fit_transform(df['Item_Type'])

df['Outlet_Identifier'] = encoder.fit_transform(df['Outlet_Identifier'])

df['Outlet_Size'] = encoder.fit_transform(df['Outlet_Size'])

df['Outlet_Location_Type'] = encoder.fit_transform(df['Outlet_Location_Type'])

df['Outlet_Type'] = encoder.fit_transform(df['Outlet_Type'])
df.head()<jupyter_output><empty_output><jupyter_text>**Splitting features and Target**<jupyter_code>X = df.iloc[:,:-1].values
y = df.iloc[:,-1].values
print(X)
print(y)<jupyter_output>[3735.138   443.4228 2097.27   ... 1193.1136 1845.5976  765.67  ]<jupyter_text>**Splitting into Train Test Split**<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2, random_state=0)
print(X.shape, X_train.shape, X_test.shape)<jupyter_output>(8523, 11) (6818, 11) (1705, 11)<jupyter_text>**Training Algortihm**<jupyter_code>from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential()

model.add(Dense(20, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(5, activation='relu'))

model.add(Dense(1)) # output layer

model.compile(optimizer='rmsprop', loss='mse')
model.fit(x = X_train, y = y_train, epochs=50)
model.summary()
loss_df = pd.DataFrame(model.history.history)
loss_df
loss_df.plot()<jupyter_output><empty_output><jupyter_text>**Model Evaluation**<jupyter_code>test_eval = model.evaluate(X_test, y_test, verbose=0)
print(test_eval)<jupyter_output>1591096.25<jupyter_text>** model evaluation on train set**<jupyter_code>train_eval = model.evaluate(X_train, y_train, verbose=0)
print(train_eval)<jupyter_output>1596897.75<jupyter_text>** Checking difference between train_eval and test_eval**<jupyter_code>model_diff = train_eval - test_eval
print(model_diff)<jupyter_output>5801.5<jupyter_text>** Train prediction on test data**<jupyter_code>train_prediction = model.predict(X_train)<jupyter_output><empty_output><jupyter_text>** Test prediction on test data**<jupyter_code>test_prediction = model.predict(X_test)
print(train_prediction)
print(test_prediction)<jupyter_output>[[2104.4558 ]
 [1590.8557 ]
 [1024.7468 ]
 ...
 [3670.7898 ]
 [ 195.01709]
 [4680.941  ]]<jupyter_text>** R Squared : R-squared measures the strength of the relationship between your model and the dependent variable on a convenient 0 –**<jupyter_code>from sklearn.metrics import r2_score
r2_train = r2_score(y_train, train_prediction)
print('R squared value of train data:', r2_train)
r2_test = r2_score(y_test, test_prediction)
print('R squared value of test data:',r2_test)<jupyter_output>R squared value of test data: 0.4563809007260504
{'fraction_non_alphanumeric': 0.1552626827947283, 'fraction_numerical': 0.03376060660769092, 'mean_word_length': 11.28381374722838, 'pattern_counts': {'":': 0, '<': 86, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '23', 'dir': 'jupyter-structured-clean-dedup', 'id': '11538', 'license': 'MIT', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2111, 'n_words': 280, 'path': 'big-market-sales-prediction.ipynb', 'repo_name': 'Nithishnj23/nj', 'size': '5539'}