Kaggle competition: Bike Sharing Demand
plt.style.use('ggplot')
 stop=set(stopwords.words('english')) 
<set_options>
train=pd.read_csv("/kaggle/input/bike-sharing-demand/train.csv")
 train.head(10 )
mpl.rc("savefig", dpi=1200 )<load_from_csv>
test=pd.read_csv("/kaggle/input/bike-sharing-demand/test.csv")
 test.head(10 )
tweet= pd.read_csv('.. /input/nlp-getting-started/train.csv')
 test=pd.read_csv('.. /input/nlp-getting-started/test.csv')
 submission= pd.read_csv('.. /input/nlp-getting-started/sample_submission.csv' )<define_variables>
train["datetime"]=train["datetime"].astype("datetime64")
 test["datetime"]=test["datetime"].astype("datetime64")
 train.dtypes
Real_len = tweet[tweet['target'] == 1].shape[0]
Not_len = tweet[tweet['target'] == 0].shape[0]<feature_engineering>
train["hour"]=train["datetime"].dt.hour
test["hour"]=test["datetime"].dt.hour
train["year"]=train["datetime"].dt.year
test["year"]=test["datetime"].dt.year
train["day of week"]=train["datetime"].dt.dayofweek
test["day of week"]=test["datetime"].dt.dayofweek
tweet['length'] = tweet['text'].apply(length )<import_modules>
y=np.log(train["count"])
 y.head()
import matplotlib.ticker as ticker<string_transform>
train=train.drop(["datetime","casual","registered","count"],1)
 train.head()
def create_corpus(target):
corpus=[]
for x in tweet[tweet['target']==target]['text'].str.split() :
for i in x:
corpus.append(i)
 return corpus<sort_values>
test=test.drop(["datetime"],1)
 test.head()
corpus=create_corpus(0)
 dic=defaultdict(int)
 for word in corpus:
if word in stop:
dic[word]+=1
top=sorted(dic.items() , key=lambda x:x[1],reverse=True)[:10]<prepare_x_and_y>
lgb=LGBMRegressor()
lgb.fit(train,y )
plt.figure(figsize=(16,5))
counter=Counter(corpus)
 most=counter.most_common()
x=[]
y=[]
for word,count in most[:40]:
if(word not in stop):
x.append(word)
 y.append(count )<feature_engineering>
sub=pd.read_csv("/kaggle/input/bike-sharing-demand/sampleSubmission.csv")
 sub.head()
def get_top_tweet_bigrams(corpus, n=None):
vec = CountVectorizer(ngram_range=(2, 2)).fit(corpus)
 bag_of_words = vec.transform(corpus)
 sum_words = bag_of_words.sum(axis=0)
 words_freq = [(word, sum_words[0, idx])for word, idx in vec.vocabulary_.items() ]
words_freq =sorted(words_freq, key = lambda x: x[1], reverse=True)
 return words_freq[:n]<concatenate>
sub["count"]=np.exp(lgb.predict(test))
sub.head()
<train_model><EOS> 
sub.to_csv("20190921.csv",index=False )