import scipy
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
df=pd.read_csv("Bike_sharing_dataset.csv", sep=";")
result=df.groupby('holiday').agg({'cnt':['mean','std']})
print (result)
cnt
mean std
holiday
0 4527.104225 1929.013947
1 3735.000000 2103.350660
result=df.groupby('weekday').agg({'cnt':['mean','std']})
print (result)
cnt
mean std
weekday
0 4228.828571 1872.496629
1 4338.123810 1793.074013
2 4510.663462 1826.911642
3 4548.538462 2038.095884
4 4667.259615 1939.433317
5 4690.288462 1874.624870
6 4550.542857 2196.693009
result=df.groupby('workingday').agg({'cnt':['mean','std']})
print (result)
cnt
mean std
workingday
0 4330.168831 2052.141245
1 4584.820000 1878.415583
result=df.groupby('weathersit').agg({'cnt':['mean','std']})
print (result)
cnt
mean std
weathersit
1 4876.786177 1879.483989
2 4035.862348 1809.109918
3 1803.285714 1240.284449
plt.scatter(df["atemp"],df["cnt"])
m,b=np.polyfit(df["atemp"],df["cnt"],1)
plt.plot(df["atemp"],m*df["atemp"]+b, color="yellow")
plt.xlabel("Temperature")
plt.ylabel("Number of bikes rented")
plt.title('Number of bikes by temperature')
plt.xlim(0,1)
plt.ylim(0,10000)
plt.show()
print("The coefficient a0 is ",b,"\nand the coefficient a1 is ",m)
The coefficient a0 is 911.333256989126
and the coefficient a1 is 7566.213065518487
result=df.groupby('season').agg({'cnt':['mean','std']})
print (result)
cnt
mean std
season
1 2604.132597 1399.942119
2 4992.331522 1695.977235
3 5644.303191 1459.800381
4 4728.162921 1699.615261
df1=df[df.season==1]
plt.scatter(df1["atemp"],df1["cnt"])
m,b=np.polyfit(df1["atemp"],df1["cnt"],1)
plt.plot(df1["atemp"],m*df1["atemp"]+b,"g")
plt.xlabel("Temperature")
plt.ylabel("Number of bikes rented")
plt.xlim(0,1)
plt.ylim(0,10000)
plt.title('Number of bikes in winter by feeling temperature')
plt.show()
print("The coefficient a0 is ",b,"\nand the coefficient a1 is ",m)
The coefficient a0 is -175.8851394405908
and the coefficient a1 is 9363.042055745667
df2=df[df.season==2]
plt.scatter(df2["atemp"],df2["cnt"])
m,b=np.polyfit(df2["atemp"],df2["cnt"],1)
plt.plot(df2["atemp"],m*df2["atemp"]+b,color="orange")
plt.xlabel("Temperature")
plt.ylabel("Number of bikes rented")
plt.xlim(0,1)
plt.ylim(0,10000)
plt.title('Number of bikes in spring by feeling temperature')
plt.show()
print("The coefficient a0 is ",b,"\nand the coefficient a1 is ",m)
The coefficient a0 is 943.7377424142888
and the coefficient a1 is 7781.158512167895
df3=df[df.season==3]
plt.scatter(df3["atemp"],df3["cnt"])
m,b=np.polyfit(df3["atemp"],df3["cnt"],1)
plt.plot(df3["atemp"],m*df3["atemp"]+b, color="purple")
plt.xlabel("Temperature")
plt.ylabel("Number of bikes rented")
plt.xlim(0,1)
plt.ylim(0,10000)
plt.title('Number of bikes in summer by feeling temperature')
plt.show()
print("The coefficient a0 is ",b,"\nand the coefficient a1 is ",m)
The coefficient a0 is 6366.46205571145
and the coefficient a1 is -1097.6235461846202
df4=df[df.season==4]
plt.scatter(df4["atemp"],df4["cnt"])
m,b=np.polyfit(df4["atemp"],df4["cnt"],1)
plt.plot(df4["atemp"],m*df4["atemp"]+b, color="black")
plt.xlabel("Temperature")
plt.ylabel("Number of bikes rented")
plt.xlim(0,1)
plt.ylim(0,10000)
plt.title('Number of bikes in fall by feeling temperature')
plt.show()
print("The coefficient a0 is ",b ,"\nand the coefficient a1 is ",m)
The coefficient a0 is 1635.5756426037642
and the coefficient a1 is 7442.356077408029