Instantly share code, notes, and snippets.
dottyz
/ story_bike_share_analyze_13.py
Created
May 2, 2019 18:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data = data.sort_values('Mean Temp').dropna().reset_index(drop=True) | |
| fig, ax = plt.subplots(figsize=(20, 10)) | |
| sns.scatterplot(x='Mean Temp', y='Casual Trips', data=data) |
dottyz
/ story_bike_share_analyze_14.py
Created
May 2, 2019 18:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from kneed import KneeLocator | |
| from scipy.optimize import curve_fit | |
| # Define the curve fitting equations | |
| def linear(x, m, b): | |
| return m*x + b | |
| def exp_growth_no_shift(x, a, b): | |
| return a * np.exp(-b * x) | |
| def exp_growth(x, a, b, c): | |
| return a * np.exp(-b * x) + c |
dottyz
/ story_bike_share_analyze_15.py
Created
May 2, 2019 18:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| popt, pcov = curve_fit(exp_growth_no_shift, x, y, maxfev=2000) | |
| # Estimate the first knee point | |
| kneedle = KneeLocator(x=x, y=exp_growth_no_shift(x, *popt), curve='convex', direction='increasing') | |
| knee_start = kneedle.knee | |
| print(knee_start) |
dottyz
/ story_bike_share_analyze_16.py
Created
May 2, 2019 18:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def logistic_growth(x, k, x0): | |
| return 1 / (1 + np.exp(-k*(x - x0))) | |
| data['Cummulative Trips'] = data['Casual Trips'].cumsum() | |
| data['Percentage Trips'] = data['Cummulative Trips'] / data['Casual Trips'].sum() | |
| x = data['Mean Temp'].values | |
| y = data['Percentage Trips'].values | |
| popt, pcov = curve_fit(logistic_growth, x, y, maxfev=2000) |
dottyz
/ story_bike_share_analyze_17.py
Created
May 2, 2019 18:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for idx, val in enumerate(x): | |
| if val > knee_start: | |
| kneedle = KneeLocator(x=x[idx:], y=y_fit[idx:], curve='concave', direction='increasing') | |
| knee_end = kneedle.knee | |
| print(knee_end) | |
| break |
OlderNewer