<jupyter_start><jupyter_text>Analysis of Automobile Inventory Data Copyright (c) 2018, Faststream Technologies Author: <NAME><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import os
import calendar
from sklearn.preprocessing import Imputer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
# from sklearn.metrics import confusion_matrix
# from sklearn.metrics import classification_report<jupyter_output><empty_output><jupyter_text>CURR and PARENT directory constants<jupyter_code>CURR_DIR = os.path.dirname(os.path.abspath('__file__'))
PARENT_DIR = os.path.abspath(os.path.join(CURR_DIR, os.pardir))<jupyter_output><empty_output><jupyter_text>Import dataset ignoring headers<jupyter_code>df = pd.read_excel(PARENT_DIR + '\\assets\\data\\items_analysis.xlsx', sheet_name='Sheet1')<jupyter_output><empty_output><jupyter_text>Dataset<jupyter_code>df.head()
# Convert uppercase to lowercase and replace empty spaces with underscore
df.columns = [i.replace(" ", "_").lower() for i in df.columns]
df.columns
# Convert 'month' and 'reqeust date' to datetime and remove time by normalization
df['month'] = pd.to_datetime(df['month'])
df['month'] = df['month'].dt.month.apply(lambda x: calendar.month_abbr[x])
df['request_date'] = (pd.to_datetime(df['request_date'])).dt.normalize()
# df['date'] = df['request_date'].dt.day
df['year'] = df['request_date'].dt.year
# Create 'Buy' and 'Make' dataframe and remove 'make_or_buy_flag'
df_buy = df[df['make_or_buy_flag'] == 'Buy'].drop(['make_or_buy_flag', 'minimum_order_quantity', 'standard_cost', 'cumulative_lt'], axis=1)
df_buy = df_buy.fillna(df_buy.mean().astype(int))

df_make = df[df['make_or_buy_flag'] == 'Make'].drop(['make_or_buy_flag', 'minimum_order_quantity'], axis=1)
df_make = df_make.fillna(df_make.mean().astype(int))
# Grouping by Item, Year, Month
df_buy_group = round(df_buy.groupby(['item_number', 'year', 'month']).mean().astype(int))
item = df_buy_group.index.levels[0]
print(df_buy_group.index.get_level_values('item_number').unique())
# print(df_buy_group.index.get_level_values('year'))
# Importing the dataset
X = df_buy.iloc[:, 2].values
y = df_buy.iloc[:, 3].values
# Splitting the dataset into the Training set and Test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=1/3, random_state=0)
X_train, X_test, y_train, y_test = X_train.reshape(-1, 1), X_test.reshape(-1, 1), y_train.reshape(-1, 1), y_test.reshape(-1, 1)
# Fitting Simple Linear Regression to the Training set
regressor = LinearRegression()
regressor.fit(X_train, y_train)
# Predicting the Test set results
y_pred = regressor.predict(X_test)
# Visualising the Training set results
plt.scatter(X_train, y_train, color='red')
plt.plot(X_train, regressor.predict(X_train), color='blue')
plt.title('Standard Cost vs Order Quantity (Training set)')
plt.xlabel('Order Quantity')
plt.ylabel('Standard Cost')
plt.show()
# Visualising the Training set results
plt.scatter(X_test, y_test, color='red')
plt.plot(X_train, regressor.predict(X_train), color='blue')
plt.title('Standard Cost vs Order Quantity (Test set)')
plt.xlabel('Order Quantity')
plt.ylabel('Standard Cost')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14211011996308828, 'fraction_numerical': 0.0064595509074131035, 'mean_word_length': 7.741935483870968, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '526002', 'license': 'MIT', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1136, 'n_words': 244, 'path': 'main/items.ipynb', 'repo_name': 'nsudhanva/auto', 'size': '3262'}