<jupyter_start><jupyter_text>Ch12 Figure6<jupyter_code># "What about a shoe makes it a hit?” He or she works with the data analysts to come up with some interesting questions: Is it the color of the shoe?  Is it some new technology? Was the shoe featured in a magazine and benefited from a network effect?

shoe_sku = np.arange(500)
color = ['red', 'blue', 'white', 'black', 'green', 'orange']
marketing_channel = ['digital news platform', 'blog', 'youtube', 'magazine']
tech = ['gps', 'step-tracker', 'extra-light-material']

data = []

for i in shoe_sku:
    
    
    sales = rd.random() * 10000
    d = [i, sales]
    
    for j in [color, marketing_channel, tech]:
        how_many = rd.randint(0, len(j))
        ary = [0 for x in range(len(j))]
        ary[:how_many] = [1 for j in range(how_many)]
        rd.shuffle(ary)
        d.extend(ary)
    
    data.append(d)
    
df = pd.DataFrame(data, columns=['sku', 'sales', 'red', 'blue', 'white', 'black', 'green', 'orange', 'digital news platform', 'blog', 'youtube', 'magazine', 'gps', 'step-tracker', 'extra-light-material'])
# df.to_csv('csv_output/ch12_fig6.csv', index=False)
df = pd.read_csv('csv_output/ch12_fig6.csv')
df.head()
df = pd.read_csv('csv_output/ch12_fig6.csv')

%matplotlib inline
sns.set_style("whitegrid")

f, ax = plt.subplots(1, figsize=(8,6))

from sklearn import linear_model
reg = linear_model.LinearRegression()
reg.fit (df.iloc[:,2:], df.iloc[:,1])
ax.barh(width=reg.coef_[::-1], bottom=[x for x in range(1,14)]);
ax.barh(width=0, bottom=0, lw=0)

ax.set_yticks(np.arange(1,14)+.5);
ax.set_yticklabels(['', 'red', 'blue', 'white', 'black', 'green', 'orange', 'digital news platform', 'blog', 'youtube', 'magazine', 'gps', 'step-tracker', 'extra-light-material'][::-1]);

ax.set_title('regression coefficient by variables');
f.savefig('svg_output/ch12_fig6.svg', format='svg')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1828752642706131, 'fraction_numerical': 0.022727272727272728, 'mean_word_length': 4.701807228915663, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '511079', 'license': 'MIT', 'n_tokens_mistral': 726, 'n_tokens_neox': 700, 'n_words': 179, 'path': 'ch12_fig6.ipynb', 'repo_name': 'dougbrose/data-science', 'size': '1892'}