<jupyter_start><jupyter_text>Contents
1. Business opportunity
2. Data collection
3. Data understanding
4. Initialisation
5. Exploratory data analysis
6. Visualizing the decision to read books without buying
7. Hypothesis testing
8. Conclusion  1. Business opportunity: A book cafe

I love books and coffee. Eventually I want to open a book cafe. I want to provide reading experience at an hourly basis. People can come and read books at a very reasonable rate for 4-6 hours or more. They would be offered a complimentary beverage during their reading experience. They can purchase other soft beverages and bakery items at a chargeable basis. In this project, I did a very rough survey to gauge the need for a book cafe. Later I plan to undertake a more robust survey described in the section  "Future Research"  2. Data collection

Target population: People aged 20-40 who read books

Sampling frame: My contacts

Sampling technique: Convenience 

Sampling size: I was confident that atleast 50% people would respond positively to reading books without buying them. At 10% sampling error and 95% confidence level we obtained the minimum required sample size of 96 

Data collection was kept anonymous because I did not want them to be conscious of what they were writing as their preferences that they might be judged. I needed the total information from a group of readers, and not tailor made suggestions for each person. So the required data was collected without intruding their privacy.

I sent the [Google form](https://forms.gle/zvAFR9VowshJW3VEA) to all my contacts through different communication channels. I received 120 responses till 20-03-2021

  3. Data understanding

The following data was captured:

| Data field | Name |Data type | Description |
| :- | -: | :-: | :-: |
| Timestamp | Timestamp|Numeric-continuous  | Timetamp of Google form submission |
| Which format do you prefer to read from? | Format|Categorical-nominal | Preferred book format |
| Choice of pairing beverage? | Beverage| Categorical-nominal | Preferred beverage while reading |
| Do you ever listen to music while reading? | Music|Categorical-nominal | Surrounded with sound while reading? |
| How do you want to read paperbacks/hardcovers ? | Target| Categorical-nominal | Target variable: Do people want to read without buying |
| How many books have you read during the last six months? | Frequency| Numeric-discrete | Frequency of reading books |
| Do you want to connect with fellow book readers? | Connect| Categorical-nominal | Do book readers want to socialise at a book cafe?|
| What genres do you enjoy reading? | Variety|Categorical-nominal | Variety of reader expected |
| Count of genres read | VarCount | Numeric-discrete| Calculated field based on the no. of genres read|


 






  4. Initialisation<jupyter_code>from initcodex import prepare, postprocess, plot1, plot2, plot3, plot4, plot5,plot6,modprocess, modeller         # Codebase 
from copy import deepcopy  
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
import matplotlib.pyplot as plt
from sklearn.preprocessing import OneHotEncoder

%matplotlib inline                                      

if __name__ == "__main__":
    dataf, format_count = prepare()                     # Accepts the input and improves column formatting for readability
    dmod = deepcopy(dataf)                              # Deepcopies the input dataframe, to be used for modelling purposes later
    dframe=modprocess(dmod)                             # Prepares the dataframe for feeding into a model
dataf.sample(5)<jupyter_output><empty_output><jupyter_text>5. Exploratory data analysis
 Visualizations<jupyter_code>plot1(dataf, format_count)                  #Book format<jupyter_output><empty_output><jupyter_text>Inference:    1. Maximum readers read from paperbacks or hard cover books. This supports our idea that people would prefer reading from phyical books.        Hence people might come to our book cafe to read books.2. Maximum no. of genres are read by ebook readers. However we do not plan on providing an ebook reading service to our customers.    3. The range of books read by paperback and hard cover book readers are same. We need to probe further to find out the total set of        different genres read by them.    4. People read more paperbacks than hard cover books, this is as expected. From here on all our analysis is on physical book readers<jupyter_code>dataf, genres, pphc, d, bv = postprocess(dataf)        #Filters only physical book readers
plot2(dataf, genres)                                   #Variety<jupyter_output><empty_output><jupyter_text>Observations:1. The no. of readers for fiction is almost double than any other category2. There are 12 genres which are read by more than 10 people in our survey    3. People who read more, read more widely<jupyter_code>plot3(pphc, d)                                      #Socializing quotient<jupyter_output><empty_output><jupyter_text>Observations:1. A high percentage(60%) of readers want to read books without buying them2. Above 85% of readers are open to socialising with other book readers. 48% readers want to meet with fellow book readers<jupyter_code>plot4(bv)                                                           #Beverage preferences<jupyter_output><empty_output><jupyter_text>Observations:1. Maximum readers prefer coffee    2. Most other readers do not prefer any beverage or prefer teaHence providing a reading experience in a cafe is a good idea.     We need to understand how many of people who do not drink coffee/tea, would want to meet fellow book readers<jupyter_code>plot5(dataf)                                                        #Non drinkers<jupyter_output><empty_output><jupyter_text>Observations:People who do not drink are interested to meet others. Hence, they would come to meet new and fellow book readers at the book cafe.<jupyter_code>dmod.Beverage.replace({'I do not drink but I know things':'No drink required','None':'No drink required','No drink necessary':'No drink required','I drink but not with books':'No drink required','Depends upon mood and time of day':'No drink required','There is no connection between books and beverage':'No drink required'},inplace=True)
dmod.Connect.replace({'Yes! no. Well maybe....':'Maybe'},inplace=True)
dmod.Music.replace({'Yes, like my life':'Yes to music','Nope':'No to music'},inplace=True)

dk = dmod[["Beverage","Connect","Music"]].groupby(['Connect','Music','Beverage'])[["Beverage"]].count()
#dk.columns=["Count"]
dk.sort_values(["Connect","Music"], ascending=[False,True], inplace=True)
dk = pd.concat([dk.iloc[0:7,:],dk.iloc[13:20,:]])<jupyter_output><empty_output><jupyter_text>Observations:1. Maximum people who drink coffee while reading want to connect with fellow book readers2. Most of the people who want to connect drink cofee3. Most people do not want to listen to music  6. Visualizing the decision to read books without buying<jupyter_code>X,y = modeller(dmod)
d=DecisionTreeClassifier(max_depth=5)
d.fit(X,y)
plt.figure(figsize=(30,30))
tree_drawn=tree.plot_tree(d, filled=True, feature_names=X.columns.tolist(), fontsize=12)
plt.show()
# Want to read books without buying ['No', 'Yes'] 
feats=d.feature_importances_.tolist()
feat_imp = pd.Series(feats, index=X.columns)
feat_imp<jupyter_output><empty_output>