<jupyter_start><jupyter_text>Programming for Data Analysis - Project.  Author: <NAME>**** Problem statement Create a data set by simulating a real-world phenomenon of your choosing. Then, rather than collect data related to the phenomenon, you should model and synthesise such data using Python [1].****  Project Background In a Manufacturing enviornment process classification and performance are vital to both company performance and customer satisfaction. A measure of this performance is OEE (Overall Equipment Effectiveness). The OEE concept is based off the following:      1. How often is the machine available to run?     2. How fast does it run when its running?     3. How many acceptable parts were produced?         The above formula is calculated as : **** Availability x Performance X Quality (A x P x Q).****  [2]. Quality is a key area of focus for Continuous Improvement (C.I) in order to improve OEE performance. In order to establish a starting point for C.I projects it is necessary to determine current process capabilities. For the purpose of this project a rough guide is used to determine the ***Process Classification***. The term  ***Six sigma*** is loosely coined in this project to order process classification. Six Sigma classifies process under 7 categories: [3].   1. Level 1 - % Yield of 31% & % defective 69%.   2. Level 2 - % Yield of 69% & % defective 31%.  3. Level 3 - % Yield of 93.3% & % defective 6.7%.  4. Level 4 - % Yield of 99.38% & % defective 0.62%.  5. Level 5 - % Yield of 99.977% & % defective 0.023%.  6. Level 6 - % Yield of 99.99966% & % defective 0.000034%.The relationship between machine age **"Years in Production"** and defective product **"Units Scrapped"** produced from the machine is used in this instance to determine the six sigma classification. It is generally accepted that the **"Scrap Rate"** will increase as machine age.  Any scrapped units are expected to negatively impact units shipped to customer. The above relationships will determine the direction used to assess and begin CI activites with the company across the 100 machines the Data is simulated for. Note:  * Pandas documentation was reffered to for all DataFrame construction - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html   * Seaborn & Matplotlib Documentation was reffered to for all plotting information - https://seaborn.pydata.org/ & https://matplotlib.org/  References: * [1] Project - Programming for Data Analysis, GMIT Project assignment. * [2] OEE, Six Sigma Material, https://www.six-sigma-material.com/OEE.html* [3] Six Sigma, Wikipedia, https://en.wikipedia.org/wiki/Six_Sigma* [4] 5 ways to apply an IF condition in Pandas DataFrame, data to fish, https://datatofish.com/if-condition-in-pandas-dataframe/* [5] Python If ... Else, w3schools,https://www.w3schools.com/python/python_conditions.asp* [6] cmdlinetips.com, How To Make Histogram in Python with Pandas and Seaborn?, https://cmdlinetips.com/2019/02/how-to-make-histogram-in-python-with-pandas-and-seaborn/<jupyter_code># importing the required libraries 
import pandas as pd
import numpy as np
import random
import matplotlib.pyplot as plt
import seaborn as sns
N = 280 # Batch Size for machines in Question
rng = np.random.default_rng() # initiate random number generator 

Machine = pd.DataFrame({"Years in Production": rng.integers(0,10, size=100), "Batches Produced": rng.integers(0, 10, size =100),}) # Used to create Data Frame
Machine ['Units Planned'] = Machine ['Batches Produced'] * N 
n1 = random.uniform(0, 0.0001) # Used to generate random values between 0 & 0.0001  
n2 = random.uniform(0, 0.05) # Used to generate random values between 0 & 0.05 
n3 = random.uniform(0, 0.1) # Used to generate random values between 0 & 0.1 

# Determine Scrap Rate dependant on machine age
Machine.loc[Machine["Years in Production"] <= 2, 'Scrap Rate'] =n1 
Machine.loc[Machine["Years in Production"] > 2, 'Scrap Rate'] = n2
Machine.loc[Machine["Years in Production"] >= 7, 'Scrap Rate'] = n3
Machine['Units Scrapped'] = Machine ['Units Planned'] * Machine ['Scrap Rate'] # Calculate Units Scrapped
Machine ['Units Shipped'] = Machine ['Units Planned'] - Machine ['Units Scrapped'] # Calculate Units Shipped
Machine ['Percentage Yield'] = Machine ["Units Shipped"] / Machine ["Units Planned"] # Calculate Percentage Yield 
# Define machine classifications 

Machine.loc[Machine['Units Shipped'] == 0, 'Process Classification'] = "Out of Service"
Machine.loc[Machine['Percentage Yield'] >= 0.31, 'Process Classification'] = "1 Sigma" 
Machine.loc[Machine['Percentage Yield'] >= 0.69, 'Process Classification'] = "2 Sigma"
Machine.loc[Machine['Percentage Yield'] >= 0.933, 'Process Classification'] = "3 Sigma" 
Machine.loc[Machine['Percentage Yield'] >= 0.9938, 'Process Classification'] = "4 Sigma" 
Machine.loc[Machine['Percentage Yield'] >= 0.99977, 'Process Classification'] = "5 Sigma"
Machine.loc[Machine['Percentage Yield'] >= 0.9999966, 'Process Classification'] = "6 Sigma"
Machine.round({'Units Scrapped':0,'Scrap Rate':7, 'Units Shipped':0,'Percentage Yield':7}) # Round values to required values and display DataFrame
print(Machine["Process Classification"].value_counts()) # Print Count of machine classifications 
# Ref [6] Display total machine classifications. 
Machine["Process Classification"].hist(bins=10, grid=False, xlabelsize=12, ylabelsize=12)
plt.xlabel("Process Classification", fontsize=12)
plt.ylabel("Count",fontsize=12)
# Ref Ianmcloughlin lecture notes
coeffs = np.polyfit(Machine["Years in Production"], Machine["Units Scrapped"], 1)
coeffs
# Ref Ianmcloughlin lecture notes

plt.plot(Machine["Years in Production"], Machine["Units Scrapped"], '.', label="Units Scrapped")
plt.plot(Machine["Years in Production"], coeffs[0] * Machine["Years in Production"] + coeffs[1], '-', label='Trend-line')

plt.legend();
sns.lineplot(data=Machine, x="Years in Production", y="Percentage Yield")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11517886994316281, 'fraction_numerical': 0.03075894349715814, 'mean_word_length': 4.971057884231537, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '510900', 'license': 'MIT', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1678, 'n_words': 679, 'path': 'Programming for Data Analysis - Project.ipynb', 'repo_name': 'JackCaff/ProgDAProject', 'size': '5988'}