<jupyter_start><jupyter_text>1) What are the factors that influence the number of bikes rented?

2) Explore the data for outliers and missing values.

3) Plot the correlation between the variables and state your comments

4) Please build a linear regression model to predict rented bike count by choosing appropriate independentvariables.

5) Coment on Model performance by using approapriate diagnostics and measures<jupyter_code>import pandas as pd
import numpy as np

import warnings
warnings.filterwarnings('ignore')

import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
sns.set(style='white', color_codes=True)
import requests #importing data SeoulBikeData.csv using the web link
url = 'https://raw.githubusercontent.com/Tech-i-s/techis-ds-wiki/master/Step%203-1%20Linear%20Regression/Project/SeoulBikeData.csv?token=<KEY>'
res = requests.get(url, allow_redirects=True)
with open('SeoulBikeData.csv','wb') as file:
    file.write(res.content)
Seoul_Bike = pd.read_csv('SeoulBikeData.csv')
print(Seoul_Bike.head())
print(Seoul_Bike.describe())
print(Seoul_Bike)
print(Seoul_Bike.info())
print(list(set(Seoul_Bike.dtypes.tolist())))
print(list(Seoul_Bike.columns))
print(Seoul_Bike.corr())
print(Seoul_Bike.isna().sum())
df_num = Seoul_Bike.select_dtypes(include = ['float64', 'int64']) #droping the non numerical variables
df_num.info()
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
sns.set(style='white', color_codes=True)
corr = df_num.corr()['Rented Bike Count']
Related_list = corr[abs(corr) > 0.1].sort_values(ascending=False)
print("There is {} strongly correlated values with Rented Bike Count:\n{}".format(len(Related_list), Related_list)) 

# from the Data SeoulBikeData we split in 2 data frame train for trainning and test for testing 
train = df_num[:10]
test = df_num[10:]
t_cor = train.corr()
t_cor # correlation between the variables in the training data

print(test.corr())
t_cor = t_cor['Rented Bike Count'] [:] # storng correlation >.3 + or - between 'Rented Bike Count' and other variables
t_cor[abs(t_cor)>0.30].sort_values(ascending=False)
print(train.info())
# test.drop(['Rented Bike Count'],axis = 1, inplace = True)
train = train[['Rented Bike Count','Hour','Temperature(C)','Humidity(%)','Wind speed (m/s)','Visibility (10m)','Dew point temperature(C)','Solar Radiation (MJ/m2)','Rainfall(mm)','Snowfall (cm)']]
test = test[['Hour','Temperature(C)','Humidity(%)','Wind speed (m/s)','Visibility (10m)','Dew point temperature(C)','Solar Radiation (MJ/m2)','Rainfall(mm)','Snowfall (cm)']]

corr = train.corr()  # using the heatmap to show the correlation between the vvariables
plt.figure(figsize=(8,8))
sns.heatmap(corr, annot=True, cmap='cubehelix_r',square=True) 
plt.show()
from sklearn.model_selection import train_test_split
train, val = train_test_split(train, test_size=0.25)
#considering only the highly correlated features for training and validation
train_x = train.drop(['Rented Bike Count'], axis = 1)
train_y = train['Rented Bike Count']             # output of the training data

val_x = val.drop(['Rented Bike Count'], axis = 1)
val_y = val['Rented Bike Count']

print('Dimension of train_x dataframe:',train_x.shape)
print('Dimension of train_y dataframe:',train_y.shape)
print('Dimension of val_x dataframe:',val_x.shape)
print('Dimension of val_y dataframe:',val_y.shape)
from sklearn.linear_model import LinearRegression

ln_reg = LinearRegression()
ln_reg.fit(train_x, train_y)


from sklearn.metrics import mean_squared_error,mean_absolute_error, r2_score

df_pred = ln_reg.predict(val_x)
print('Mean Absolute Error of linear regression:',mean_absolute_error(df_pred, val_y))
print('Mean Square Error of linear regression:', mean_squared_error(df_pred, val_y))
print('R_Squared Score of linear regression:', r2_score(df_pred, val_y))


#final prediction on test data
predic_test = ln_reg.predict(test)

#Create Sample Submission file 
submission_data = pd.DataFrame({'Hour':test.Hour,'Pred_RentedBike':predic_test})
submission_data
val_y = pd.DataFrame(val_y)
val_y['Predicted'] = submission_data['Pred_RentedBike']

val_y
from sklearn.linear_model import Ridge

ridge = Ridge()
ridge

ridge.fit(train_x,train_y)
ridge_score = ridge.score(val_x,val_y)
coeff_used = np.sum(ridge.coef_ != 0)
ridge.coef_

print("training score",ridge_score)
print("number of feature used:",coeff_used)
from sklearn.linear_model import Lasso 
lasso = Lasso()
lasso

lasso.fit(train_x,train_y)
lasso_score = lasso.score(val_x,val_y)
coeff_used = np.sum(lasso.coef_ != 0)
lasso.coef_

print("training score",lasso_score)
print("number of feature used:",coeff_used)<jupyter_output>training score -52.659325983911465
number of feature used: 4
{'fraction_non_alphanumeric': 0.12307692307692308, 'fraction_numerical': 0.013305613305613306, 'mean_word_length': 6.0029112081513825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 1, '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': '664317', 'license': 'Unlicense', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1676, 'n_words': 406, 'path': 'linear_Reg_project.ipynb', 'repo_name': 'jeanpaulnazon/jeanpaulnazon.github.io', 'size': '4834'}