<jupyter_start><jupyter_text>Predicting Price for Wholesale and Internet segmentsFirst thing we need to do is predict the average prices in the wholesale and internet segments for North America, Europe Africa, Asia Pacific, and Latin America.This helps us make more accurate decisions in BSG and identify if we'll hit the shareholder expectations for the period.<jupyter_code>#let's grab a few packages for stats
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

#Let's set some variables that we'll change each round
#Change this year to the year being predicted (i.e. if you're predicting year 16, enter '16')
predictionYear = 17 

#Load the dataset from our bsg_prices_actual - Sheet1.csv
df = pd.read_csv('bsg_prices_actual - Sheet1.csv')
df<jupyter_output><empty_output><jupyter_text>FunctionsHere we'll create some functions for reuse:1. Slope Intercept2. Print Slope as Formula3. Hypothetical Slope and Intercept from our data4. Print the Predicted Year using Hypothetical Slope and Intercept<jupyter_code>#1. Slope Intercept Function
#Function to find the slope intercept of a first degree polynomial
def getSlope(x,y): #pass in the x value, y value, and a string for printing
    slope, intercept = np.polyfit(x,y,1).round(decimals = 4) #compute the slope
    return slope, intercept

#2. Print Slope as Formulas
#Function to print the slope
def printSlope(x,y,string):
    slope, intercept = np.polyfit(x,y,1).round(decimals = 4)
    printed_string = string + '= ' + str(slope) + 'x + ' + str(intercept)
    return printed_string 

#3. Hypothetical Slope and Intercept from our data
x_theor = np.array([10,predictionYear]) #set x_theor as it will be used in all our Linear Models
def getYTheor(slope, x_theor, intercept): #pass in the slope, x_theor, and intercept
    y_theor = slope * x_theor + intercept
    return y_theor

#4. Print Predicted Year using Hypothetical Slope and Intercept
def printPrediction(slope, intercept, string): 
    prediction = 'Year ' + str(predictionYear) + ' ' + string +' predicted price: ' + str(slope * predictionYear + intercept)
    return prediction<jupyter_output><empty_output><jupyter_text>Find Slope Intercept for each segment<jupyter_code>#variable assignments
x = np.array(df['YEAR'])
y_na_internet = np.array(df['NA_PRICE_INTERNET_INDUSTRY_AVERAGE'])
y_na_wholesale = np.array(df['NA_PRICE_WHOLESALE_INDUSTRY_AVERAGE'])
y_eu_internet = np.array(df['EU_PRICE_INTERNET_INDUSTRY_AVERAGE'])
y_eu_wholesale = np.array(df['EU_PRICE_WHOLESALE_INDUSTRY_AVERAGE'])
y_ap_internet = np.array(df['AP_PRICE_INTERNET_INDUSTRY_AVERAGE'])
y_ap_wholesale = np.array(df['AP_PRICE_WHOLESALE_INDUSTRY_AVERAGE'])
y_la_internet = np.array(df['LA_PRICE_INTERNET_INDUSTRY_AVERAGE'])
y_la_wholesale = np.array(df['LA_PRICE_WHOLESALE_INDUSTRY_AVERAGE'])

#print the slope in y=mx+b form
print(printSlope(x,y_na_internet,'NA Internet'))
print(printSlope(x,y_na_wholesale,'NA Wholesale'))
print(printSlope(x,y_eu_internet,'EU Internet'))
print(printSlope(x,y_eu_wholesale,'EU Wholesale'))
print(printSlope(x,y_ap_internet,'AP Internet'))
print(printSlope(x,y_ap_wholesale,'AP Wholesale'))
print(printSlope(x,y_la_internet,'LA Internet'))
print(printSlope(x,y_la_wholesale,'LA Wholesale'))<jupyter_output>NA Internet= 4.3768x + 26.7175
NA Wholesale= 2.9486x + 20.2857
EU Internet= 4.5393x + 33.0307
EU Wholesale= 2.8614x + 27.6629
AP Internet= 3.4693x + 38.375
AP Wholesale= 2.2346x + 29.7339
LA Internet= 3.2246x + 48.9239
LA Wholesale= 1.9343x + 39.4557<jupyter_text>North America Internet and Wholesale PricingThis is in dollars per pair of shoes<jupyter_code>#grab the slope and intercepts for NA Internet and Wholesale segments
na_internet_slope, na_internet_intercept = getSlope(x,y_na_internet)
na_wholesale_slope,na_wholesale_intercept = getSlope(x,y_na_wholesale)

#set the y theoretical for NA Internet and Wholesale
internet_y_theor = getYTheor(na_internet_slope, x_theor, na_internet_intercept)
wholesale_y_theor = getYTheor(na_wholesale_slope,x_theor,na_wholesale_intercept)

#print the predicted price
print(printPrediction(na_internet_slope, na_internet_intercept, 'Internet'))
print(printPrediction(na_wholesale_slope, na_wholesale_intercept, 'Wholesale'))

#plot the anscombe data and theoretical lines
_ = plt.plot(x,y_na_internet,marker='.', linestyle='none')
_ = plt.plot(x_theor,internet_y_theor)
_ = plt.plot(x,y_na_wholesale,marker='.', linestyle='none')
_ = plt.plot(x_theor,wholesale_y_theor)

#label the axes
plt.xlabel('Year')
plt.ylabel('Price')
plt.title('North America')
plt.show()<jupyter_output>Year 17 Internet predicted price: 101.12310000000001
Year 17 Wholesale predicted price: 70.4119<jupyter_text>Europe Africa Internet and Wholesale Pricingdollars per pair<jupyter_code>#grab the slope and intercepts for NA Internet and Wholesale segments
eu_internet_slope, eu_internet_intercept = getSlope(x,y_eu_internet)
eu_wholesale_slope,eu_wholesale_intercept = getSlope(x,y_eu_wholesale)

#set the y theoretical for NA Internet and Wholesale
internet_y_theor = getYTheor(eu_internet_slope, x_theor, eu_internet_intercept)
wholesale_y_theor = getYTheor(eu_wholesale_slope,x_theor,eu_wholesale_intercept)

#print the predicted price
print(printPrediction(eu_internet_slope, eu_internet_intercept, 'Internet'))
print(printPrediction(eu_wholesale_slope, eu_wholesale_intercept, 'Wholesale'))

#plot the anscombe data and theoretical lines
_ = plt.plot(x,y_eu_internet,marker='.', linestyle='none')
_ = plt.plot(x_theor,internet_y_theor)
_ = plt.plot(x,y_eu_wholesale,marker='.', linestyle='none')
_ = plt.plot(x_theor,wholesale_y_theor)

#label the axes
plt.xlabel('Year')
plt.ylabel('Price')
plt.title('Europe Africa')
plt.show()<jupyter_output>Year 17 Internet predicted price: 110.1988
Year 17 Wholesale predicted price: 76.3067<jupyter_text>Asia Pacific Internet and Wholesale Pricingdollars per pair<jupyter_code>#grab the slope and intercepts for NA Internet and Wholesale segments
ap_internet_slope, ap_internet_intercept = getSlope(x,y_ap_internet)
ap_wholesale_slope,ap_wholesale_intercept = getSlope(x,y_ap_wholesale)

#set the y theoretical for NA Internet and Wholesale
internet_y_theor = getYTheor(ap_internet_slope, x_theor, ap_internet_intercept)
wholesale_y_theor = getYTheor(ap_wholesale_slope,x_theor,ap_wholesale_intercept)

#print the predicted price
print(printPrediction(ap_internet_slope, ap_internet_intercept, 'Internet'))
print(printPrediction(ap_wholesale_slope, ap_wholesale_intercept, 'Wholesale'))

#plot the anscombe data and theoretical lines
_ = plt.plot(x,y_ap_internet,marker='.', linestyle='none')
_ = plt.plot(x_theor,internet_y_theor)
_ = plt.plot(x,y_ap_wholesale,marker='.', linestyle='none')
_ = plt.plot(x_theor,wholesale_y_theor)

#label the axes
plt.xlabel('Year')
plt.ylabel('Price')
plt.title('Asia Pacific')
plt.show()<jupyter_output>Year 17 Internet predicted price: 97.3531
Year 17 Wholesale predicted price: 67.7221<jupyter_text>Latin America Internet and Wholesale Pricingdollars per pair<jupyter_code>#grab the slope and intercepts for NA Internet and Wholesale segments
la_internet_slope, la_internet_intercept = getSlope(x,y_la_internet)
la_wholesale_slope, la_wholesale_intercept = getSlope(x,y_la_wholesale)

#set the y theoretical for NA Internet and Wholesale
internet_y_theor = getYTheor(la_internet_slope, x_theor, la_internet_intercept)
wholesale_y_theor = getYTheor(la_wholesale_slope,x_theor, la_wholesale_intercept)

#print the predicted price
print(printPrediction(la_internet_slope, la_internet_intercept, 'Internet'))
print(printPrediction(la_wholesale_slope, la_wholesale_intercept, 'Wholesale'))

#plot the anscombe data and theoretical lines
_ = plt.plot(x,y_la_internet,marker='.', linestyle='none')
_ = plt.plot(x_theor,internet_y_theor)
_ = plt.plot(x,y_la_wholesale,marker='.', linestyle='none')
_ = plt.plot(x_theor,wholesale_y_theor)

#label the axes
plt.xlabel('Year')
plt.ylabel('Price')
plt.title('Latin America')
plt.show()<jupyter_output>Year 17 Internet predicted price: 103.74210000000001
Year 17 Wholesale predicted price: 72.33879999999999
{'fraction_non_alphanumeric': 0.09470304975922954, 'fraction_numerical': 0.025435238918384985, 'mean_word_length': 7.852459016393443, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '69777', 'license': 'MIT', 'n_tokens_mistral': 3179, 'n_tokens_neox': 2966, 'n_words': 660, 'path': 'Price_Predictions.ipynb', 'repo_name': 'KiminyCricket/BSG_Projections', 'size': '8099'}